Skip to content

Commit 5bdbb25

Browse files
authored
Merge pull request ceph#55455 from sseshasa/wip-fix-cluster-log-level-str
common/LogEntry: Add log level to str helper for fmt::formatter<LogEntry> Reviewed-by: Kefu Chai <[email protected]> Reviewed-by: Radoslaw Zarzynski <[email protected]> Reviewed-by: Ronen Friedman <[email protected]>
2 parents 08fe40f + 0bd01b9 commit 5bdbb25

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/common/LogEntry.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ struct LogEntry {
125125
void dump(ceph::Formatter *f) const;
126126
static void generate_test_instances(std::list<LogEntry*>& o);
127127
static clog_type str_to_level(std::string const &str);
128+
static std::string_view level_to_str(clog_type t) {
129+
switch (t) {
130+
case CLOG_DEBUG:
131+
return "DBG";
132+
case CLOG_INFO:
133+
return "INF";
134+
case CLOG_SEC:
135+
return "SEC";
136+
case CLOG_WARN:
137+
return "WRN";
138+
case CLOG_ERROR:
139+
return "ERR";
140+
case CLOG_UNKNOWN:
141+
return "UNKNOWN";
142+
}
143+
return "???";
144+
}
128145
};
129146
WRITE_CLASS_ENCODER_FEATURES(LogEntry)
130147

@@ -208,8 +225,9 @@ template <> struct fmt::formatter<EntityName> : fmt::formatter<std::string_view>
208225
template <> struct fmt::formatter<LogEntry> : fmt::formatter<std::string_view> {
209226
template <typename FormatContext>
210227
auto format(const LogEntry& e, FormatContext& ctx) {
211-
return fmt::format_to(ctx.out(), "{} {} ({}) {} : {} {} {}",
212-
e.stamp, e.name, e.rank, e.seq, e.channel, e.prio, e.msg);
228+
return fmt::format_to(ctx.out(), "{} {} ({}) {} : {} [{}] {}",
229+
e.stamp, e.name, e.rank, e.seq, e.channel,
230+
LogEntry::level_to_str(e.prio), e.msg);
213231
}
214232
};
215233

0 commit comments

Comments
 (0)