Logging: Fix fmt errors after rebasing with master
fmt was updated during the clang-format update, which breaks the previous implementation of FmtLogMessage Changes were: * Move definition of FmtLogMessage into log.h to use variadic templates as FMT_VARIADIC was removed To supplement the change above: * Move Entry and CreateEntry into log.h * Add LogEntry in backend.cpp
This commit is contained in:
parent
ab4ba71f3e
commit
eee388588e
3 changed files with 37 additions and 33 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <fmt/format.h>
|
||||
#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 <typename... Args>
|
||||
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__)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue