]>
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"
14 void LogEntryKey::encode(bufferlist
& bl
, uint64_t features
) const
16 ::encode(who
, bl
, features
);
21 void LogEntryKey::decode(bufferlist::iterator
& bl
)
29 void LogEntryKey::dump(Formatter
*f
) const
31 f
->dump_stream("who") << who
;
32 f
->dump_stream("stamp") << stamp
;
33 f
->dump_unsigned("seq", seq
);
36 void LogEntryKey::generate_test_instances(list
<LogEntryKey
*>& o
)
38 o
.push_back(new LogEntryKey
);
39 o
.push_back(new LogEntryKey(entity_inst_t(), utime_t(1,2), 34));
42 clog_type
LogEntry::str_to_level(std::string
const &str
)
44 std::string level_str
= str
;
45 std::transform(level_str
.begin(), level_str
.end(), level_str
.begin(),
46 [](char c
) {return std::tolower(c
);});
48 if (level_str
== "debug") {
50 } else if (level_str
== "info") {
52 } else if (level_str
== "sec") {
54 } else if (level_str
== "warn" || level_str
== "warning") {
56 } else if (level_str
== "error" || level_str
== "err") {
65 int clog_type_to_syslog_level(clog_type t
)
84 clog_type
string_to_clog_type(const string
& s
)
86 if (boost::iequals(s
, "debug") ||
87 boost::iequals(s
, "dbg"))
89 if (boost::iequals(s
, "info") ||
90 boost::iequals(s
, "inf"))
92 if (boost::iequals(s
, "warning") ||
93 boost::iequals(s
, "warn") ||
94 boost::iequals(s
, "wrn"))
96 if (boost::iequals(s
, "error") ||
97 boost::iequals(s
, "err"))
99 if (boost::iequals(s
, "security") ||
100 boost::iequals(s
, "sec"))
106 int string_to_syslog_level(string s
)
108 if (boost::iequals(s
, "debug"))
110 if (boost::iequals(s
, "info") ||
111 boost::iequals(s
, "notice"))
113 if (boost::iequals(s
, "warning") ||
114 boost::iequals(s
, "warn"))
116 if (boost::iequals(s
, "error") ||
117 boost::iequals(s
, "err"))
119 if (boost::iequals(s
, "crit") ||
120 boost::iequals(s
, "critical") ||
121 boost::iequals(s
, "emerg"))
124 // err on the side of noise!
128 int string_to_syslog_facility(string s
)
130 if (boost::iequals(s
, "auth"))
132 if (boost::iequals(s
, "authpriv"))
134 if (boost::iequals(s
, "cron"))
136 if (boost::iequals(s
, "daemon"))
138 if (boost::iequals(s
, "ftp"))
140 if (boost::iequals(s
, "kern"))
142 if (boost::iequals(s
, "local0"))
144 if (boost::iequals(s
, "local1"))
146 if (boost::iequals(s
, "local2"))
148 if (boost::iequals(s
, "local3"))
150 if (boost::iequals(s
, "local4"))
152 if (boost::iequals(s
, "local5"))
154 if (boost::iequals(s
, "local6"))
156 if (boost::iequals(s
, "local7"))
158 if (boost::iequals(s
, "lpr"))
160 if (boost::iequals(s
, "mail"))
162 if (boost::iequals(s
, "news"))
164 if (boost::iequals(s
, "syslog"))
166 if (boost::iequals(s
, "user"))
168 if (boost::iequals(s
, "uucp"))
175 string
clog_type_to_string(clog_type t
)
194 void LogEntry::log_to_syslog(string level
, string facility
)
196 int min
= string_to_syslog_level(level
);
197 int l
= clog_type_to_syslog_level(prio
);
199 int f
= string_to_syslog_facility(facility
);
200 syslog(l
| f
, "%s %llu : %s",
201 stringify(who
).c_str(),
202 (long long unsigned)seq
,
207 void LogEntry::encode(bufferlist
& bl
, uint64_t features
) const
209 ENCODE_START(4, 2, bl
);
211 ::encode(who
, bl
, features
);
216 ::encode(channel
, bl
);
221 void LogEntry::decode(bufferlist::iterator
& bl
)
223 DECODE_START_LEGACY_COMPAT_LEN(4, 2, 2, bl
);
232 ::decode(channel
, bl
);
234 // prior to having logging channels we only had a cluster log.
235 // Ensure we keep that appearance when the other party has no
236 // clue of what a 'channel' is.
237 channel
= CLOG_CHANNEL_CLUSTER
;
245 void LogEntry::dump(Formatter
*f
) const
247 f
->dump_stream("who") << who
;
248 f
->dump_stream("name") << name
;
249 f
->dump_stream("stamp") << stamp
;
250 f
->dump_unsigned("seq", seq
);
251 f
->dump_string("channel", channel
);
252 f
->dump_stream("priority") << prio
;
253 f
->dump_string("message", msg
);
256 void LogEntry::generate_test_instances(list
<LogEntry
*>& o
)
258 o
.push_back(new LogEntry
);
264 void LogSummary::encode(bufferlist
& bl
, uint64_t features
) const
266 ENCODE_START(2, 2, bl
);
267 ::encode(version
, bl
);
268 ::encode(tail
, bl
, features
);
272 void LogSummary::decode(bufferlist::iterator
& bl
)
274 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
275 ::decode(version
, bl
);
279 for (auto& p
: tail
) {
280 keys
.insert(p
.key());
284 void LogSummary::dump(Formatter
*f
) const
286 f
->dump_unsigned("version", version
);
287 f
->open_array_section("tail");
288 for (list
<LogEntry
>::const_iterator p
= tail
.begin(); p
!= tail
.end(); ++p
) {
289 f
->open_object_section("entry");
296 void LogSummary::generate_test_instances(list
<LogSummary
*>& o
)
298 o
.push_back(new LogSummary
);