1 #ifndef CEPH_LOGCLIENT_H
2 #define CEPH_LOGCLIENT_H
4 #include "common/LogEntry.h"
5 #include "common/ostream_temp.h"
6 #include "common/ref.h"
7 #include "include/health.h"
8 #include "crimson/net/Fwd.h"
10 #include <seastar/core/future.hh>
11 #include <seastar/core/gate.hh>
12 #include <seastar/core/lowres_clock.hh>
13 #include <seastar/core/shared_ptr.hh>
14 #include <seastar/core/timer.hh>
31 template<typename Message
> using Ref
= boost::intrusive_ptr
<Message
>;
32 namespace crimson::net
{
36 enum class log_flushing_t
{
41 int parse_log_client_options(CephContext
*cct
,
42 std::map
<std::string
,std::string
> &log_to_monitors
,
43 std::map
<std::string
,std::string
> &log_to_syslog
,
44 std::map
<std::string
,std::string
> &log_channels
,
45 std::map
<std::string
,std::string
> &log_prios
,
46 std::map
<std::string
,std::string
> &log_to_graylog
,
47 std::map
<std::string
,std::string
> &log_to_graylog_host
,
48 std::map
<std::string
,std::string
> &log_to_graylog_port
,
52 /** Manage where we output to and at which priority
54 * Not to be confused with the LogClient, which is the almighty coordinator
55 * of channels. We just deal with the boring part of the logging: send to
56 * syslog, send to file, generate LogEntry and queue it for the LogClient.
58 * Past queueing the LogEntry, the LogChannel is done with the whole thing.
59 * LogClient will deal with sending and handling of LogEntries.
61 class LogChannel
: public LoggerSinkSet
64 LogChannel(LogClient
*lc
, const std::string
&channel
);
65 LogChannel(LogClient
*lc
, const std::string
&channel
,
66 const std::string
&facility
, const std::string
&prio
);
69 return OstreamTemp(CLOG_DEBUG
, this);
71 void debug(std::stringstream
&s
) final
{
72 do_log(CLOG_DEBUG
, s
);
75 * Convenience function mapping health status to
76 * the appropriate cluster log severity.
78 OstreamTemp
health(health_status_t health
) {
87 // Invalid health_status_t value
91 OstreamTemp
info() final
{
92 return OstreamTemp(CLOG_INFO
, this);
94 void info(std::stringstream
&s
) final
{
97 OstreamTemp
warn() final
{
98 return OstreamTemp(CLOG_WARN
, this);
100 void warn(std::stringstream
&s
) final
{
101 do_log(CLOG_WARN
, s
);
103 OstreamTemp
error() final
{
104 return OstreamTemp(CLOG_ERROR
, this);
106 void error(std::stringstream
&s
) final
{
107 do_log(CLOG_ERROR
, s
);
109 OstreamTemp
sec() final
{
110 return OstreamTemp(CLOG_SEC
, this);
112 void sec(std::stringstream
&s
) final
{
116 void set_log_to_monitors(bool v
);
117 void set_log_to_syslog(bool v
) {
120 void set_log_channel(const std::string
& v
) {
123 void set_log_prio(const std::string
& v
) {
126 void set_syslog_facility(const std::string
& v
) {
129 const std::string
& get_log_prio() const { return log_prio
; }
130 const std::string
& get_log_channel() const { return log_channel
; }
131 const std::string
& get_syslog_facility() const { return syslog_facility
; }
132 bool must_log_to_syslog() const { return log_to_syslog
; }
134 * Do we want to log to syslog?
136 * @return true if log_to_syslog is true and both channel and prio
137 * are not empty; false otherwise.
139 bool do_log_to_syslog() {
140 return must_log_to_syslog() &&
141 !log_prio
.empty() && !log_channel
.empty();
143 bool must_log_to_monitors() { return log_to_monitors
; }
145 bool do_log_to_graylog() {
146 return (graylog
!= nullptr);
149 using Ref
= seastar::lw_shared_ptr
<LogChannel
>;
152 * update config values from parsed k/v std::map for each config option
154 * Pick out the relevant value based on our channel.
156 void update_config(std::map
<std::string
,std::string
> &log_to_monitors
,
157 std::map
<std::string
,std::string
> &log_to_syslog
,
158 std::map
<std::string
,std::string
> &log_channels
,
159 std::map
<std::string
,std::string
> &log_prios
,
160 std::map
<std::string
,std::string
> &log_to_graylog
,
161 std::map
<std::string
,std::string
> &log_to_graylog_host
,
162 std::map
<std::string
,std::string
> &log_to_graylog_port
,
166 void do_log(clog_type prio
, std::stringstream
& ss
) final
;
167 void do_log(clog_type prio
, const std::string
& s
) final
;
171 std::string log_channel
;
172 std::string log_prio
;
173 std::string syslog_facility
;
175 bool log_to_monitors
;
176 seastar::shared_ptr
<ceph::logging::Graylog
> graylog
;
179 using LogChannelRef
= LogChannel::Ref
;
184 enum logclient_flag_t
{
189 LogClient(crimson::net::Messenger
*m
, logclient_flag_t flags
);
191 virtual ~LogClient() = default;
193 seastar::future
<> handle_log_ack(Ref
<MLogAck
> m
);
194 MessageURef
get_mon_log_message(log_flushing_t flush_flag
);
195 bool are_pending() const;
197 LogChannelRef
create_channel() {
198 return create_channel(CLOG_CHANNEL_DEFAULT
);
201 LogChannelRef
create_channel(const std::string
& name
);
203 void destroy_channel(const std::string
& name
) {
204 channels
.erase(name
);
211 uint64_t get_next_seq();
212 entity_addrvec_t
get_myaddrs() const;
213 const EntityName
& get_myname() const;
214 entity_name_t
get_myrank();
215 version_t
queue(LogEntry
&entry
);
217 seastar::future
<> set_fsid(const uuid_d
& fsid
);
220 MessageURef
_get_mon_log_message();
222 crimson::net::Messenger
*messenger
;
224 version_t last_log_sent
;
226 std::deque
<LogEntry
> log_queue
;
228 std::map
<std::string
, LogChannelRef
> channels
;