]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/LogEntry: specialize fmt::formatter<LogEntry>
authorKefu Chai <tchaikov@gmail.com>
Sat, 27 Aug 2022 03:00:20 +0000 (11:00 +0800)
committerKefu Chai <tchaikov@gmail.com>
Sat, 27 Aug 2022 15:59:24 +0000 (23:59 +0800)
so we can use the formatter defined for `LogEntry` in fmtlib v9.
in this new version of fmtlib, it is required to define a specialization
for the formatted type even when it comes to the types with an override of
operator<<(). since we already have an override for `LogEntry`, let's define
the specialization for `fmt::formatter<LogEntry>`.

this change should address the FTBFS when building with fmtlib v9.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/common/LogEntry.h

index 124a20799207046d835326eb46298fe031016dd7..3ddebbd3043c062eff3b4df7b7c3a3caa8748bc7 100644 (file)
 #ifndef CEPH_LOGENTRY_H
 #define CEPH_LOGENTRY_H
 
+#include <fmt/format.h>
+
 #include "include/utime.h"
+#include "msg/msg_fmt.h"
 #include "msg/msg_types.h"
 #include "common/entity_name.h"
 #include "ostream_temp.h"
@@ -191,4 +194,19 @@ inline std::ostream& operator<<(std::ostream& out, const LogEntry& e)
              << e.channel << " " << e.prio << " " << e.msg;
 }
 
+template <> struct fmt::formatter<EntityName> : fmt::formatter<std::string_view> {
+  template <typename FormatContext>
+  auto format(const EntityName& e, FormatContext& ctx) {
+    return formatter<std::string_view>::format(e.to_str(), ctx);
+  }
+};
+
+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);
+  }
+};
+
 #endif