]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/LogEntry: Add log level to str helper for fmt::formatter<LogEntry>
authorSridhar Seshasayee <sseshasa@redhat.com>
Tue, 19 Dec 2023 15:05:50 +0000 (20:35 +0530)
committerSridhar Seshasayee <sseshasa@redhat.com>
Mon, 5 Feb 2024 17:00:18 +0000 (22:30 +0530)
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 <sseshasa@redhat.com>
src/common/LogEntry.h

index 3ddebbd3043c062eff3b4df7b7c3a3caa8748bc7..5de0b71efba24d05216e785524d41cf07f9dae9c 100644 (file)
@@ -125,6 +125,23 @@ struct LogEntry {
   void dump(ceph::Formatter *f) const;
   static void generate_test_instances(std::list<LogEntry*>& 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<EntityName> : fmt::formatter<std::string_view>
 template <> struct fmt::formatter<LogEntry> : fmt::formatter<std::string_view> {
   template <typename FormatContext>
   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);
   }
 };