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/ceph_mutex.h"
21 #include "common/ostream_temp.h"
22 #include "common/ref.h"
23 #include "include/health.h"
42 struct clog_targets_conf_t
{
43 std::string log_to_monitors
;
44 std::string log_to_syslog
;
45 std::string log_channels
;
46 std::string log_prios
;
47 std::string log_to_graylog
;
48 std::string log_to_graylog_host
;
49 std::string log_to_graylog_port
;
50 uuid_d fsid
; // only 16B. Simpler as a copy.
54 /** Manage where we output to and at which priority
56 * Not to be confused with the LogClient, which is the almighty coordinator
57 * of channels. We just deal with the boring part of the logging: send to
58 * syslog, send to file, generate LogEntry and queue it for the LogClient.
60 * Past queueing the LogEntry, the LogChannel is done with the whole thing.
61 * LogClient will deal with sending and handling of LogEntries.
63 class LogChannel
: public OstreamTemp::OstreamTempSink
67 LogChannel(CephContext
*cct
, LogClient
*lc
, const std::string
&channel
);
68 LogChannel(CephContext
*cct
, LogClient
*lc
,
69 const std::string
&channel
,
70 const std::string
&facility
,
71 const std::string
&prio
);
74 return OstreamTemp(CLOG_DEBUG
, this);
76 void debug(std::stringstream
&s
) {
77 do_log(CLOG_DEBUG
, s
);
80 * Convenience function mapping health status to
81 * the appropriate cluster log severity.
83 OstreamTemp
health(health_status_t health
) {
92 // Invalid health_status_t value
97 return OstreamTemp(CLOG_INFO
, this);
99 void info(std::stringstream
&s
) {
100 do_log(CLOG_INFO
, s
);
103 return OstreamTemp(CLOG_WARN
, this);
105 void warn(std::stringstream
&s
) {
106 do_log(CLOG_WARN
, s
);
108 OstreamTemp
error() {
109 return OstreamTemp(CLOG_ERROR
, this);
111 void error(std::stringstream
&s
) {
112 do_log(CLOG_ERROR
, s
);
115 return OstreamTemp(CLOG_SEC
, this);
117 void sec(std::stringstream
&s
) {
121 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 std::shared_ptr
<LogChannel
> Ref
;
157 * Query the configuration database in conf_cct for configuration
158 * parameters. Pick out the relevant values based on our channel name.
159 * Update the logger configuration based on these values.
161 * Return a collection of configuration strings.
163 clog_targets_conf_t
parse_client_options(CephContext
* conf_cct
);
165 void do_log(clog_type prio
, std::stringstream
& ss
);
166 void do_log(clog_type prio
, const std::string
& s
);
171 ceph::mutex channel_lock
= ceph::make_mutex("LogChannel::channel_lock");
172 std::string log_channel
;
173 std::string log_prio
;
174 std::string syslog_facility
;
176 bool log_to_monitors
;
177 std::shared_ptr
<ceph::logging::Graylog
> graylog
;
180 * update config values from parsed k/v std::map for each config option
182 void update_config(const clog_targets_conf_t
& conf_strings
);
184 clog_targets_conf_t
parse_log_client_options(CephContext
* conf_cct
);
187 typedef LogChannel::Ref LogChannelRef
;
192 enum logclient_flag_t
{
197 LogClient(CephContext
*cct
, Messenger
*m
, MonMap
*mm
,
198 logclient_flag_t flags
);
200 virtual ~LogClient() {
204 bool handle_log_ack(MLogAck
*m
);
205 ceph::ref_t
<Message
> get_mon_log_message(bool flush
);
208 LogChannelRef
create_channel() {
209 return create_channel(CLOG_CHANNEL_DEFAULT
);
212 LogChannelRef
create_channel(const std::string
& name
) {
214 if (channels
.count(name
))
217 c
= std::make_shared
<LogChannel
>(cct
, this, name
);
223 void destroy_channel(const std::string
& name
) {
224 if (channels
.count(name
))
225 channels
.erase(name
);
232 uint64_t get_next_seq();
233 entity_addrvec_t
get_myaddrs();
234 const EntityName
& get_myname();
235 entity_name_t
get_myrank();
236 version_t
queue(LogEntry
&entry
);
240 ceph::ref_t
<Message
> _get_mon_log_message();
244 Messenger
*messenger
;
247 ceph::mutex log_lock
= ceph::make_mutex("LogClient::log_lock");
248 version_t last_log_sent
;
250 std::deque
<LogEntry
> log_queue
;
252 std::map
<std::string
, LogChannelRef
> channels
;