From 0bd01b9c1a78c13d404c667e49ed3b9cb931fb47 Mon Sep 17 00:00:00 2001 From: Sridhar Seshasayee Date: Tue, 19 Dec 2023 20:35:50 +0530 Subject: [PATCH] common/LogEntry: Add log level to str helper for fmt::formatter The Ceph cluster logs were missing the string equivalent [INF|WRN|ERR|DBG] representation of the 'prio' field. This was broken since the introduction of commit 2901943618f071060f72d69cf632a4097e439df4 of PR: https://github.com/ceph/ceph/pull/47830. This probably caused false positives in teuthology testing and particularly for those tests that check for cluster badness by parsing the cluster logs. The fix involves adding a static helper function to the LogEntry struct. This function returns the string appropriate representation of the log level similar to the operator<<() for LogEntry. Fixes: https://tracker.ceph.com/issues/64314 Signed-off-by: Sridhar Seshasayee --- src/common/LogEntry.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/common/LogEntry.h b/src/common/LogEntry.h index 3ddebbd3043..5de0b71efba 100644 --- a/src/common/LogEntry.h +++ b/src/common/LogEntry.h @@ -125,6 +125,23 @@ struct LogEntry { void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list& o); static clog_type str_to_level(std::string const &str); + static std::string_view level_to_str(clog_type t) { + switch (t) { + case CLOG_DEBUG: + return "DBG"; + case CLOG_INFO: + return "INF"; + case CLOG_SEC: + return "SEC"; + case CLOG_WARN: + return "WRN"; + case CLOG_ERROR: + return "ERR"; + case CLOG_UNKNOWN: + return "UNKNOWN"; + } + return "???"; + } }; WRITE_CLASS_ENCODER_FEATURES(LogEntry) @@ -204,8 +221,9 @@ template <> struct fmt::formatter : fmt::formatter template <> struct fmt::formatter : fmt::formatter { template auto format(const LogEntry& e, FormatContext& ctx) { - return fmt::format_to(ctx.out(), "{} {} ({}) {} : {} {} {}", - e.stamp, e.name, e.rank, e.seq, e.channel, e.prio, e.msg); + return fmt::format_to(ctx.out(), "{} {} ({}) {} : {} [{}] {}", + e.stamp, e.name, e.rank, e.seq, e.channel, + LogEntry::level_to_str(e.prio), e.msg); } }; -- 2.39.5