From c892cea02936e509b73ea9ce8ae9302a0bdc2b4b Mon Sep 17 00:00:00 2001 From: Daniel Lim Wee Soong Date: Wed, 21 Mar 2018 23:36:45 +0800 Subject: [PATCH] Place FmtLogMessage's definition in backend.cpp I decided to overload LogMessage because I don't see a reason to come up with a new function name just for this, but if you guys want me to overload FmtLogMessage instead I'm fine with that. --- src/common/logging/backend.cpp | 7 +++++-- src/common/logging/backend.h | 24 ++++++++++++++++++++++ src/common/logging/log.h | 37 +++++----------------------------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index fdd0480c9..768f3f22f 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -153,9 +153,12 @@ void LogMessage(Class log_class, Level log_level, const char* filename, unsigned PrintColoredMessage(entry); } -void LogEntry(Entry& entry) { - if (filter && !filter->CheckMessage(entry.log_class, entry.log_level)) +void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, + const char* function, const char* format, const fmt::format_args& args) { + if (filter && !filter->CheckMessage(log_class, log_level)) return; + Entry entry = + CreateEntry(log_class, log_level, filename, line_num, function, fmt::vformat(format, args)); PrintColoredMessage(entry); } diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index d5b9834e1..7e81efb23 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h @@ -14,6 +14,26 @@ namespace Log { class Filter; +/** + * A log entry. Log entries are store in a structured format to permit more varied output + * formatting on different frontends, as well as facilitating filtering and aggregation. + */ +struct Entry { + std::chrono::microseconds timestamp; + Class log_class; + Level log_level; + std::string filename; + unsigned int line_num; + std::string function; + std::string message; + + Entry() = default; + Entry(Entry&& o) = default; + + Entry& operator=(Entry&& o) = default; + Entry& operator=(const Entry& o) = default; +}; + /** * Returns the name of the passed log class as a C-string. Subclasses are separated by periods * instead of underscores as in the enumeration. @@ -25,5 +45,9 @@ const char* GetLogClassName(Class log_class); */ const char* GetLevelName(Level log_level); +/// Creates a log entry by formatting the given source location, and message. +Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, + const char* function, std::string message); + void SetFilter(Filter* filter); } // namespace Log diff --git a/src/common/logging/log.h b/src/common/logging/log.h index b272a8611..cfaa59487 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -99,33 +99,6 @@ enum class Class : ClassType { Count ///< Total number of logging classes }; -/** - * A log entry. Log entries are store in a structured format to permit more varied output - * formatting on different frontends, as well as facilitating filtering and aggregation. - */ -struct Entry { - std::chrono::microseconds timestamp; - Class log_class; - Level log_level; - std::string filename; - unsigned int line_num; - std::string function; - std::string message; - - Entry() = default; - Entry(Entry&& o) = default; - - Entry& operator=(Entry&& o) = default; - Entry& operator=(const Entry& o) = default; -}; - -/// Creates a log entry by formatting the given source location, and message. -Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, - const char* function, std::string message); - -// Logs an Entry -void LogEntry(Entry& entry); - /// Logs a message to the global logger. void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, const char* function, @@ -139,14 +112,14 @@ void LogMessage(Class log_class, Level log_level, const char* filename, unsigned #endif ; -/// Logs a message to the global logger, this time with 100% moar fmtlib +/// Logs a message to the global logger, using fmt +void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, + const char* function, const char* format, const fmt::format_args& args); + template void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, const char* function, const char* format, const Args&... args) { - Entry entry = CreateEntry(log_class, log_level, filename, line_num, function, - fmt::format(format, args...)); - - LogEntry(entry); + LogMessage(log_class, log_level, filename, line_num, function, format, fmt::make_args(args...)); } } // namespace Log