]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/LogClient.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_LOGCLIENT_H
16 #define CEPH_LOGCLIENT_H
19 #include "common/LogEntry.h"
20 #include "common/Mutex.h"
39 int parse_log_client_options(CephContext
*cct
,
40 map
<string
,string
> &log_to_monitors
,
41 map
<string
,string
> &log_to_syslog
,
42 map
<string
,string
> &log_channels
,
43 map
<string
,string
> &log_prios
,
44 map
<string
,string
> &log_to_graylog
,
45 map
<string
,string
> &log_to_graylog_host
,
46 map
<string
,string
> &log_to_graylog_port
,
53 LogClientTemp(clog_type type_
, LogChannel
&parent_
);
54 LogClientTemp(const LogClientTemp
&rhs
);
58 std::ostream
& operator<<(const T
& rhs
)
69 /** Manage where we output to and at which priority
71 * Not to be confused with the LogClient, which is the almighty coordinator
72 * of channels. We just deal with the boring part of the logging: send to
73 * syslog, send to file, generate LogEntry and queue it for the LogClient.
75 * Past queueing the LogEntry, the LogChannel is done with the whole thing.
76 * LogClient will deal with sending and handling of LogEntries.
82 LogChannel(CephContext
*cct
, LogClient
*lc
, const std::string
&channel
);
83 LogChannel(CephContext
*cct
, LogClient
*lc
,
84 const std::string
&channel
,
85 const std::string
&facility
,
86 const std::string
&prio
);
88 LogClientTemp
debug() {
89 return LogClientTemp(CLOG_DEBUG
, *this);
91 void debug(std::stringstream
&s
) {
92 do_log(CLOG_DEBUG
, s
);
94 LogClientTemp
info() {
95 return LogClientTemp(CLOG_INFO
, *this);
97 void info(std::stringstream
&s
) {
100 LogClientTemp
warn() {
101 return LogClientTemp(CLOG_WARN
, *this);
103 void warn(std::stringstream
&s
) {
104 do_log(CLOG_WARN
, s
);
106 LogClientTemp
error() {
107 return LogClientTemp(CLOG_ERROR
, *this);
109 void error(std::stringstream
&s
) {
110 do_log(CLOG_ERROR
, s
);
112 LogClientTemp
sec() {
113 return LogClientTemp(CLOG_SEC
, *this);
115 void sec(std::stringstream
&s
) {
119 void set_log_to_monitors(bool v
) {
122 void set_log_to_syslog(bool v
) {
125 void set_log_channel(const std::string
& v
) {
128 void set_log_prio(const std::string
& v
) {
131 void set_syslog_facility(const std::string
& v
) {
134 std::string
get_log_prio() { return log_prio
; }
135 std::string
get_log_channel() { return log_channel
; }
136 std::string
get_syslog_facility() { return syslog_facility
; }
137 bool must_log_to_syslog() { return log_to_syslog
; }
139 * Do we want to log to syslog?
141 * @return true if log_to_syslog is true and both channel and prio
142 * are not empty; false otherwise.
144 bool do_log_to_syslog() {
145 return must_log_to_syslog() &&
146 !log_prio
.empty() && !log_channel
.empty();
148 bool must_log_to_monitors() { return log_to_monitors
; }
150 bool do_log_to_graylog() {
151 return (graylog
!= nullptr);
154 typedef shared_ptr
<LogChannel
> Ref
;
157 * update config values from parsed k/v map for each config option
159 * Pick out the relevant value based on our channel.
161 void update_config(map
<string
,string
> &log_to_monitors
,
162 map
<string
,string
> &log_to_syslog
,
163 map
<string
,string
> &log_channels
,
164 map
<string
,string
> &log_prios
,
165 map
<string
,string
> &log_to_graylog
,
166 map
<string
,string
> &log_to_graylog_host
,
167 map
<string
,string
> &log_to_graylog_port
,
171 void do_log(clog_type prio
, std::stringstream
& ss
);
172 void do_log(clog_type prio
, const std::string
& s
);
178 std::string log_channel
;
179 std::string log_prio
;
180 std::string syslog_facility
;
182 bool log_to_monitors
;
183 shared_ptr
<ceph::logging::Graylog
> graylog
;
186 friend class LogClientTemp
;
189 typedef LogChannel::Ref LogChannelRef
;
194 enum logclient_flag_t
{
199 LogClient(CephContext
*cct
, Messenger
*m
, MonMap
*mm
,
200 enum logclient_flag_t flags
);
201 virtual ~LogClient() {
205 bool handle_log_ack(MLogAck
*m
);
206 Message
*get_mon_log_message(bool flush
);
209 LogChannelRef
create_channel() {
210 return create_channel(CLOG_CHANNEL_DEFAULT
);
213 LogChannelRef
create_channel(const std::string
& name
) {
215 if (channels
.count(name
))
218 c
= std::make_shared
<LogChannel
>(cct
, this, name
);
224 void destroy_channel(const std::string
& name
) {
225 if (channels
.count(name
))
226 channels
.erase(name
);
233 uint64_t get_next_seq();
234 const entity_inst_t
& get_myinst();
235 const EntityName
& get_myname();
236 version_t
queue(LogEntry
&entry
);
239 Message
*_get_mon_log_message();
243 Messenger
*messenger
;
247 version_t last_log_sent
;
248 std::atomic
<uint64_t> last_log
;
249 std::deque
<LogEntry
> log_queue
;
251 std::map
<std::string
, LogChannelRef
> channels
;