From 2901943618f071060f72d69cf632a4097e439df4 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 27 Aug 2022 11:00:20 +0800 Subject: [PATCH] common/LogEntry: specialize fmt::formatter 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`. this change should address the FTBFS when building with fmtlib v9. Signed-off-by: Kefu Chai --- src/common/LogEntry.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/common/LogEntry.h b/src/common/LogEntry.h index 124a207992070..3ddebbd3043c0 100644 --- a/src/common/LogEntry.h +++ b/src/common/LogEntry.h @@ -15,7 +15,10 @@ #ifndef CEPH_LOGENTRY_H #define CEPH_LOGENTRY_H +#include + #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 : fmt::formatter { + template + auto format(const EntityName& e, FormatContext& ctx) { + return formatter::format(e.to_str(), ctx); + } +}; + +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); + } +}; + #endif -- 2.39.5