]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/LogEntry.cc
40bdbea2b3ac72e929d6515ecabb684d0bf66b86
2 #include <boost/algorithm/string/predicate.hpp>
6 #include "include/stringify.h"
11 void LogEntryKey::encode(bufferlist
& bl
, uint64_t features
) const
13 ::encode(who
, bl
, features
);
18 void LogEntryKey::decode(bufferlist::iterator
& bl
)
26 void LogEntryKey::dump(Formatter
*f
) const
28 f
->dump_stream("who") << who
;
29 f
->dump_stream("stamp") << stamp
;
30 f
->dump_unsigned("seq", seq
);
33 void LogEntryKey::generate_test_instances(list
<LogEntryKey
*>& o
)
35 o
.push_back(new LogEntryKey
);
36 o
.push_back(new LogEntryKey(entity_inst_t(), utime_t(1,2), 34));
41 int clog_type_to_syslog_level(clog_type t
)
60 clog_type
string_to_clog_type(const string
& s
)
62 if (boost::iequals(s
, "debug") ||
63 boost::iequals(s
, "dbg"))
65 if (boost::iequals(s
, "info") ||
66 boost::iequals(s
, "inf"))
68 if (boost::iequals(s
, "warning") ||
69 boost::iequals(s
, "warn") ||
70 boost::iequals(s
, "wrn"))
72 if (boost::iequals(s
, "error") ||
73 boost::iequals(s
, "err"))
75 if (boost::iequals(s
, "security") ||
76 boost::iequals(s
, "sec"))
82 int string_to_syslog_level(string s
)
84 if (boost::iequals(s
, "debug"))
86 if (boost::iequals(s
, "info") ||
87 boost::iequals(s
, "notice"))
89 if (boost::iequals(s
, "warning") ||
90 boost::iequals(s
, "warn"))
92 if (boost::iequals(s
, "error") ||
93 boost::iequals(s
, "err"))
95 if (boost::iequals(s
, "crit") ||
96 boost::iequals(s
, "critical") ||
97 boost::iequals(s
, "emerg"))
100 // err on the side of noise!
104 int string_to_syslog_facility(string s
)
106 if (boost::iequals(s
, "auth"))
108 if (boost::iequals(s
, "authpriv"))
110 if (boost::iequals(s
, "cron"))
112 if (boost::iequals(s
, "daemon"))
114 if (boost::iequals(s
, "ftp"))
116 if (boost::iequals(s
, "kern"))
118 if (boost::iequals(s
, "local0"))
120 if (boost::iequals(s
, "local1"))
122 if (boost::iequals(s
, "local2"))
124 if (boost::iequals(s
, "local3"))
126 if (boost::iequals(s
, "local4"))
128 if (boost::iequals(s
, "local5"))
130 if (boost::iequals(s
, "local6"))
132 if (boost::iequals(s
, "local7"))
134 if (boost::iequals(s
, "lpr"))
136 if (boost::iequals(s
, "mail"))
138 if (boost::iequals(s
, "news"))
140 if (boost::iequals(s
, "syslog"))
142 if (boost::iequals(s
, "user"))
144 if (boost::iequals(s
, "uucp"))
151 string
clog_type_to_string(clog_type t
)
170 void LogEntry::log_to_syslog(string level
, string facility
)
172 int min
= string_to_syslog_level(level
);
173 int l
= clog_type_to_syslog_level(prio
);
175 int f
= string_to_syslog_facility(facility
);
176 syslog(l
| f
, "%s %llu : %s",
177 stringify(who
).c_str(),
178 (long long unsigned)seq
,
183 void LogEntry::encode(bufferlist
& bl
, uint64_t features
) const
185 ENCODE_START(4, 2, bl
);
187 ::encode(who
, bl
, features
);
192 ::encode(channel
, bl
);
197 void LogEntry::decode(bufferlist::iterator
& bl
)
199 DECODE_START_LEGACY_COMPAT_LEN(4, 2, 2, bl
);
208 ::decode(channel
, bl
);
210 // prior to having logging channels we only had a cluster log.
211 // Ensure we keep that appearance when the other party has no
212 // clue of what a 'channel' is.
213 channel
= CLOG_CHANNEL_CLUSTER
;
221 void LogEntry::dump(Formatter
*f
) const
223 f
->dump_stream("who") << who
;
224 f
->dump_stream("name") << name
;
225 f
->dump_stream("stamp") << stamp
;
226 f
->dump_unsigned("seq", seq
);
227 f
->dump_string("channel", channel
);
228 f
->dump_stream("priority") << prio
;
229 f
->dump_string("message", msg
);
232 void LogEntry::generate_test_instances(list
<LogEntry
*>& o
)
234 o
.push_back(new LogEntry
);
240 void LogSummary::encode(bufferlist
& bl
, uint64_t features
) const
242 ENCODE_START(2, 2, bl
);
243 ::encode(version
, bl
);
244 ::encode(tail
, bl
, features
);
248 void LogSummary::decode(bufferlist::iterator
& bl
)
250 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
251 ::decode(version
, bl
);
255 for (auto& p
: tail
) {
256 keys
.insert(p
.key());
260 void LogSummary::dump(Formatter
*f
) const
262 f
->dump_unsigned("version", version
);
263 f
->open_array_section("tail");
264 for (list
<LogEntry
>::const_iterator p
= tail
.begin(); p
!= tail
.end(); ++p
) {
265 f
->open_object_section("entry");
272 void LogSummary::generate_test_instances(list
<LogSummary
*>& o
)
274 o
.push_back(new LogSummary
);