diff options
Diffstat (limited to '')
-rw-r--r-- | logging.hh | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -69,7 +69,7 @@ struct is_to_string_available<T, std::void_t<decltype(std::to_string(std::declva { }; -// Same mechanism for t.toLogString() +// Same mechanism for t.toLogString() and t.toStructuredLogString() template <typename T, typename = void> struct is_toLogString_available : std::false_type { @@ -81,6 +81,16 @@ struct is_toLogString_available<T, std::void_t<decltype(std::declval<T>().toLogS }; template <typename T, typename = void> +struct is_toStructuredLogString_available : std::false_type +{ +}; + +template <typename T> +struct is_toStructuredLogString_available<T, std::void_t<decltype(std::declval<T>().toStructuredLogString())>> : std::true_type +{ +}; + +template <typename T, typename = void> struct is_toString_available : std::false_type { }; @@ -103,6 +113,9 @@ struct Loggable : public Logr::Loggable if constexpr (std::is_same_v<T, std::string>) { return _t; } + else if constexpr (is_toStructuredLogString_available<T>::value) { + return _t.toStructuredLogString(); + } else if constexpr (is_toLogString_available<T>::value) { return _t.toLogString(); } @@ -202,6 +215,7 @@ extern bool g_slogStructured; // SLOG(g_log<<Logger::Warning<<"Unable to parse configuration file '"<<configname<<"'"<<endl, // startupLog->error("No such file", "Unable to parse configuration file", "config_file", Logging::Loggable(configname)); // +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define SLOG(oldStyle, slogCall) \ do { \ if (g_slogStructured) { \ @@ -210,11 +224,12 @@ extern bool g_slogStructured; else { \ oldStyle; \ } \ - } while (0); + } while (0) #else // No structured logging (e.g. auth) +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define SLOG(oldStyle, slogCall) \ do { \ oldStyle; \ - } while (0); + } while (0) #endif // RECURSOR |