From a37be70b3bba3ed647c99af7fb0abd37bea61d70 Mon Sep 17 00:00:00 2001 From: Bailey Chittle Date: Thu, 22 Dec 2022 11:01:39 -0500 Subject: [PATCH] formats log messages (at least for default) --- include/spdlog/details/log_attr.h | 4 ++-- include/spdlog/pattern_formatter-inl.h | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/log_attr.h b/include/spdlog/details/log_attr.h index 5a177e27..757661b3 100644 --- a/include/spdlog/details/log_attr.h +++ b/include/spdlog/details/log_attr.h @@ -12,8 +12,8 @@ namespace details { struct attr { - std::string key; - std::string value; + std::string_view key; + std::string_view value; public: attr(std::initializer_list l) { diff --git a/include/spdlog/pattern_formatter-inl.h b/include/spdlog/pattern_formatter-inl.h index 01afbe6f..6b8ac54d 100644 --- a/include/spdlog/pattern_formatter-inl.h +++ b/include/spdlog/pattern_formatter-inl.h @@ -1010,6 +1010,16 @@ public: } // fmt_helper::append_string_view(msg.msg(), dest); fmt_helper::append_string_view(msg.payload, dest); + + if (msg.attributes.size() > 0) { + fmt_helper::append_string_view(" | ", dest); + for (const details::attr& a : msg.attributes) { + fmt_helper::append_string_view(a.key, dest); + fmt_helper::append_string_view("=\"", dest); + fmt_helper::append_string_view(a.value, dest); + fmt_helper::append_string_view("\", ", dest); + } + } } private: