]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/LogEntry.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 #include <boost/algorithm/string/predicate.hpp>
9 #include "include/stringify.h"
17 using ceph::bufferlist
;
20 using ceph::Formatter
;
25 void LogEntryKey::dump(Formatter
*f
) const
27 f
->dump_stream("rank") << rank
;
28 f
->dump_stream("stamp") << stamp
;
29 f
->dump_unsigned("seq", seq
);
32 void LogEntryKey::generate_test_instances(list
<LogEntryKey
*>& o
)
34 o
.push_back(new LogEntryKey
);
35 o
.push_back(new LogEntryKey(entity_name_t::CLIENT(1234), utime_t(1,2), 34));
38 clog_type
LogEntry::str_to_level(std::string
const &str
)
40 std::string level_str
= str
;
41 std::transform(level_str
.begin(), level_str
.end(), level_str
.begin(),
42 [](char c
) {return std::tolower(c
);});
44 if (level_str
== "debug") {
46 } else if (level_str
== "info") {
48 } else if (level_str
== "sec") {
50 } else if (level_str
== "warn" || level_str
== "warning") {
52 } else if (level_str
== "error" || level_str
== "err") {
61 int clog_type_to_syslog_level(clog_type t
)
80 clog_type
string_to_clog_type(const string
& s
)
82 if (boost::iequals(s
, "debug") ||
83 boost::iequals(s
, "dbg"))
85 if (boost::iequals(s
, "info") ||
86 boost::iequals(s
, "inf"))
88 if (boost::iequals(s
, "warning") ||
89 boost::iequals(s
, "warn") ||
90 boost::iequals(s
, "wrn"))
92 if (boost::iequals(s
, "error") ||
93 boost::iequals(s
, "err"))
95 if (boost::iequals(s
, "security") ||
96 boost::iequals(s
, "sec"))
102 int string_to_syslog_level(string s
)
104 if (boost::iequals(s
, "debug"))
106 if (boost::iequals(s
, "info") ||
107 boost::iequals(s
, "notice"))
109 if (boost::iequals(s
, "warning") ||
110 boost::iequals(s
, "warn"))
112 if (boost::iequals(s
, "error") ||
113 boost::iequals(s
, "err"))
115 if (boost::iequals(s
, "crit") ||
116 boost::iequals(s
, "critical") ||
117 boost::iequals(s
, "emerg"))
120 // err on the side of noise!
124 int string_to_syslog_facility(string s
)
126 if (boost::iequals(s
, "auth"))
128 if (boost::iequals(s
, "authpriv"))
130 if (boost::iequals(s
, "cron"))
132 if (boost::iequals(s
, "daemon"))
134 if (boost::iequals(s
, "ftp"))
136 if (boost::iequals(s
, "kern"))
138 if (boost::iequals(s
, "local0"))
140 if (boost::iequals(s
, "local1"))
142 if (boost::iequals(s
, "local2"))
144 if (boost::iequals(s
, "local3"))
146 if (boost::iequals(s
, "local4"))
148 if (boost::iequals(s
, "local5"))
150 if (boost::iequals(s
, "local6"))
152 if (boost::iequals(s
, "local7"))
154 if (boost::iequals(s
, "lpr"))
156 if (boost::iequals(s
, "mail"))
158 if (boost::iequals(s
, "news"))
160 if (boost::iequals(s
, "syslog"))
162 if (boost::iequals(s
, "user"))
164 if (boost::iequals(s
, "uucp"))
171 string
clog_type_to_string(clog_type t
)
190 void LogEntry::log_to_syslog(string level
, string facility
) const
192 int min
= string_to_syslog_level(level
);
193 int l
= clog_type_to_syslog_level(prio
);
195 int f
= string_to_syslog_facility(facility
);
196 syslog(l
| f
, "%s %s %llu : %s",
198 stringify(rank
).c_str(),
199 (long long unsigned)seq
,
204 void LogEntry::encode(bufferlist
& bl
, uint64_t features
) const
206 assert(HAVE_FEATURE(features
, SERVER_NAUTILUS
));
207 ENCODE_START(5, 5, bl
);
211 encode(addrs
, bl
, features
);
220 void LogEntry::decode(bufferlist::const_iterator
& bl
)
222 DECODE_START_LEGACY_COMPAT_LEN(5, 2, 2, bl
);
229 addrs
.v
.push_back(who
.addr
);
238 // prior to having logging channels we only had a cluster log.
239 // Ensure we keep that appearance when the other party has no
240 // clue of what a 'channel' is.
241 channel
= CLOG_CHANNEL_CLUSTER
;
261 void LogEntry::dump(Formatter
*f
) const
263 f
->dump_stream("name") << name
;
264 f
->dump_stream("rank") << rank
;
265 f
->dump_object("addrs", addrs
);
266 f
->dump_stream("stamp") << stamp
;
267 f
->dump_unsigned("seq", seq
);
268 f
->dump_string("channel", channel
);
269 f
->dump_stream("priority") << prio
;
270 f
->dump_string("message", msg
);
273 void LogEntry::generate_test_instances(list
<LogEntry
*>& o
)
275 o
.push_back(new LogEntry
);
281 void LogSummary::build_ordered_tail_legacy(list
<LogEntry
> *tail
) const
284 // channel -> (begin, end)
285 map
<string
,pair
<list
<pair
<uint64_t,LogEntry
>>::const_iterator
,
286 list
<pair
<uint64_t,LogEntry
>>::const_iterator
>> pos
;
287 for (auto& i
: tail_by_channel
) {
288 pos
.emplace(i
.first
, make_pair(i
.second
.begin(), i
.second
.end()));
291 uint64_t min_seq
= 0;
292 list
<pair
<uint64_t,LogEntry
>>::const_iterator
*minp
= 0;
293 for (auto& i
: pos
) {
294 if (i
.second
.first
== i
.second
.second
) {
297 if (min_seq
== 0 || i
.second
.first
->first
< min_seq
) {
298 min_seq
= i
.second
.first
->first
;
299 minp
= &i
.second
.first
;
305 tail
->push_back((*minp
)->second
);
310 void LogSummary::encode(bufferlist
& bl
, uint64_t features
) const
312 assert(HAVE_FEATURE(features
, SERVER_MIMIC
));
313 ENCODE_START(4, 3, bl
);
316 encode(tail_by_channel
, bl
, features
);
317 encode(channel_info
, bl
);
318 recent_keys
.encode(bl
);
322 void LogSummary::decode(bufferlist::const_iterator
& bl
)
324 DECODE_START_LEGACY_COMPAT_LEN(4, 2, 2, bl
);
327 decode(tail_by_channel
, bl
);
329 decode(channel_info
, bl
);
330 recent_keys
.decode(bl
);
334 for (auto& i
: tail_by_channel
) {
335 for (auto& e
: i
.second
) {
336 keys
.insert(e
.second
.key());
341 void LogSummary::dump(Formatter
*f
) const
343 f
->dump_unsigned("version", version
);
344 f
->open_object_section("tail_by_channel");
345 for (auto& i
: tail_by_channel
) {
346 f
->open_object_section(i
.first
.c_str());
347 for (auto& j
: i
.second
) {
348 string s
= stringify(j
.first
);
349 f
->dump_object(s
.c_str(), j
.second
);
356 void LogSummary::generate_test_instances(list
<LogSummary
*>& o
)
358 o
.push_back(new LogSummary
);