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"
21 #include "include/health.h"
40 int parse_log_client_options(CephContext *cct,
41 map<string,string> &log_to_monitors,
42 map<string,string> &log_to_syslog,
43 map<string,string> &log_channels,
44 map<string,string> &log_prios,
45 map<string,string> &log_to_graylog,
46 map<string,string> &log_to_graylog_host,
47 map<string,string> &log_to_graylog_port,
54 LogClientTemp(clog_type type_, LogChannel &parent_);
55 LogClientTemp(const LogClientTemp &rhs);
59 std::ostream& operator<<(const T& rhs)
70 /** Manage where we output to and at which priority
72 * Not to be confused with the LogClient, which is the almighty coordinator
73 * of channels. We just deal with the boring part of the logging: send to
74 * syslog, send to file, generate LogEntry and queue it for the LogClient.
76 * Past queueing the LogEntry, the LogChannel is done with the whole thing.
77 * LogClient will deal with sending and handling of LogEntries.
83 LogChannel(CephContext *cct, LogClient *lc, const std::string &channel);
84 LogChannel(CephContext *cct, LogClient *lc,
85 const std::string &channel,
86 const std::string &facility,
87 const std::string &prio);
89 LogClientTemp debug() {
90 return LogClientTemp(CLOG_DEBUG, *this);
92 void debug(std::stringstream &s) {
93 do_log(CLOG_DEBUG, s);
96 * Convenience function mapping health status to
97 * the appropriate cluster log severity.
99 LogClientTemp health(health_status_t health) {
108 // Invalid health_status_t value
112 LogClientTemp info() {
113 return LogClientTemp(CLOG_INFO, *this);
115 void info(std::stringstream &s) {
116 do_log(CLOG_INFO, s);
118 LogClientTemp warn() {
119 return LogClientTemp(CLOG_WARN, *this);
121 void warn(std::stringstream &s) {
122 do_log(CLOG_WARN, s);
124 LogClientTemp error() {
125 return LogClientTemp(CLOG_ERROR, *this);
127 void error(std::stringstream &s) {
128 do_log(CLOG_ERROR, s);
130 LogClientTemp sec() {
131 return LogClientTemp(CLOG_SEC, *this);
133 void sec(std::stringstream &s) {
137 void set_log_to_monitors(bool v) {
140 void set_log_to_syslog(bool v) {
143 void set_log_channel(const std::string& v) {
146 void set_log_prio(const std::string& v) {
149 void set_syslog_facility(const std::string& v) {
152 std::string get_log_prio() { return log_prio; }
153 std::string get_log_channel() { return log_channel; }
154 std::string get_syslog_facility() { return syslog_facility; }
155 bool must_log_to_syslog() { return log_to_syslog; }
157 * Do we want to log to syslog?
159 * @return true if log_to_syslog is true and both channel and prio
160 * are not empty; false otherwise.
162 bool do_log_to_syslog() {
163 return must_log_to_syslog() &&
164 !log_prio.empty() && !log_channel.empty();
166 bool must_log_to_monitors() { return log_to_monitors; }
168 bool do_log_to_graylog() {
169 return (graylog != nullptr);
172 typedef shared_ptr<LogChannel> Ref;
175 * update config values from parsed k/v map for each config option
177 * Pick out the relevant value based on our channel.
179 void update_config(map<string,string> &log_to_monitors,
180 map<string,string> &log_to_syslog,
181 map<string,string> &log_channels,
182 map<string,string> &log_prios,
183 map<string,string> &log_to_graylog,
184 map<string,string> &log_to_graylog_host,
185 map<string,string> &log_to_graylog_port,
189 void do_log(clog_type prio, std::stringstream& ss);
190 void do_log(clog_type prio, const std::string& s);
196 std::string log_channel;
197 std::string log_prio;
198 std::string syslog_facility;
200 bool log_to_monitors;
201 shared_ptr<ceph::logging::Graylog> graylog;
204 friend class LogClientTemp;
207 typedef LogChannel::Ref LogChannelRef;
212 enum logclient_flag_t {
217 LogClient(CephContext *cct, Messenger *m, MonMap *mm,
218 enum logclient_flag_t flags);
219 virtual ~LogClient() {
223 bool handle_log_ack(MLogAck *m);
224 Message *get_mon_log_message(bool flush);
227 LogChannelRef create_channel() {
228 return create_channel(CLOG_CHANNEL_DEFAULT);
231 LogChannelRef create_channel(const std::string& name) {
233 if (channels.count(name))
236 c = std::make_shared<LogChannel>(cct, this, name);
242 void destroy_channel(const std::string& name) {
243 if (channels.count(name))
244 channels.erase(name);
251 uint64_t get_next_seq();
252 const entity_inst_t& get_myinst();
253 const EntityName& get_myname();
254 version_t queue(LogEntry &entry);
257 Message *_get_mon_log_message();
261 Messenger *messenger;
265 version_t last_log_sent;
267 std::deque<LogEntry> log_queue;
269 std::map<std::string, LogChannelRef> channels;