diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index ef530e3ee..20b4fe5ea 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -265,15 +265,11 @@ void LogMessage(Class log_class, Level log_level, const char* filename, unsigned Impl::Instance().PushEntry(std::move(entry)); } -void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, - const char* function, const char* format, fmt::ArgList args) { +void LogEntry(Entry& entry) { auto filter = Impl::Instance().GetGlobalFilter(); - if (!filter.CheckMessage(log_class, log_level)) + if (!filter.CheckMessage(entry.log_class, entry.log_level)) return; - Entry entry = - CreateEntry(log_class, log_level, filename, line_num, function, fmt::format(format, args)); - Impl::Instance().PushEntry(std::move(entry)); } } // namespace Log diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index 5feef5dd4..0bf9b8fd7 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h @@ -18,26 +18,6 @@ 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; -}; - /** * Interface for logging backends. As loggers can be created and removed at runtime, this can be * used by a frontend for adding a custom logging backend as needed @@ -112,10 +92,6 @@ 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); - /** * The global filter will prevent any messages from even being processed if they are filtered. Each * backend can have a filter, but if the level is lower than the global filter, the backend will diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 59ba3a778..ba3831ea6 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "common/common_types.h" @@ -98,6 +99,33 @@ 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, @@ -112,10 +140,14 @@ void LogMessage(Class log_class, Level log_level, const char* filename, unsigned ; /// Logs a message to the global logger, this time with 100% moar fmtlib +template void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, - const char* function, const char* format, fmt::ArgList); + const char* function, const char* format, const Args & ... args) { + Entry entry = + CreateEntry(log_class, log_level, filename, line_num, function, fmt::format(format, args...)); -FMT_VARIADIC(void, FmtLogMessage, Class, Level, const char*, unsigned int, const char*, const char*) + LogEntry(entry); +} } // namespace Log @@ -163,4 +195,4 @@ FMT_VARIADIC(void, FmtLogMessage, Class, Level, const char*, unsigned int, const __func__, fmt, ##__VA_ARGS__) #define NGLOG_CRITICAL(log_class, fmt, ...) \ ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Critical, __FILE__, __LINE__, \ - __func__, fmt, ##__VA_ARGS__) +__func__, fmt, ##__VA_ARGS__)