|
|
@ -16,15 +16,6 @@ |
|
|
|
|
|
|
|
|
namespace Common::Log { |
|
|
namespace Common::Log { |
|
|
|
|
|
|
|
|
// trims up to and including the last of ../, ..\, src/, src\ in a string |
|
|
|
|
|
constexpr const char* TrimSourcePath(std::string_view source) { |
|
|
|
|
|
const auto rfind = [source](const std::string_view match) { |
|
|
|
|
|
return source.rfind(match) == source.npos ? 0 : (source.rfind(match) + match.size()); |
|
|
|
|
|
}; |
|
|
|
|
|
auto idx = (std::max)({rfind("src/"), rfind("src\\"), rfind("../"), rfind("..\\")}); |
|
|
|
|
|
return source.data() + idx; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Logs a message to the global logger, using fmt |
|
|
/// Logs a message to the global logger, using fmt |
|
|
void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename, |
|
|
void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename, |
|
|
unsigned int line_num, const char* function, fmt::string_view format, |
|
|
unsigned int line_num, const char* function, fmt::string_view format, |
|
|
@ -42,7 +33,7 @@ void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsig |
|
|
#ifdef _DEBUG |
|
|
#ifdef _DEBUG |
|
|
#define LOG_TRACE(log_class, ...) \ |
|
|
#define LOG_TRACE(log_class, ...) \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Trace, \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Trace, \ |
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ |
|
|
|
|
|
|
|
|
__FILE__, __LINE__, __func__, \ |
|
|
__VA_ARGS__) |
|
|
__VA_ARGS__) |
|
|
#else |
|
|
#else |
|
|
#define LOG_TRACE(log_class, fmt, ...) (void(0)) |
|
|
#define LOG_TRACE(log_class, fmt, ...) (void(0)) |
|
|
@ -50,21 +41,21 @@ void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsig |
|
|
|
|
|
|
|
|
#define LOG_DEBUG(log_class, ...) \ |
|
|
#define LOG_DEBUG(log_class, ...) \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Debug, \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Debug, \ |
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ |
|
|
|
|
|
|
|
|
__FILE__, __LINE__, __func__, \ |
|
|
__VA_ARGS__) |
|
|
__VA_ARGS__) |
|
|
#define LOG_INFO(log_class, ...) \ |
|
|
#define LOG_INFO(log_class, ...) \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Info, \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Info, \ |
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ |
|
|
|
|
|
|
|
|
__FILE__, __LINE__, __func__, \ |
|
|
__VA_ARGS__) |
|
|
__VA_ARGS__) |
|
|
#define LOG_WARNING(log_class, ...) \ |
|
|
#define LOG_WARNING(log_class, ...) \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Warning, \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Warning, \ |
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ |
|
|
|
|
|
|
|
|
__FILE__, __LINE__, __func__, \ |
|
|
__VA_ARGS__) |
|
|
__VA_ARGS__) |
|
|
#define LOG_ERROR(log_class, ...) \ |
|
|
#define LOG_ERROR(log_class, ...) \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Error, \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Error, \ |
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ |
|
|
|
|
|
|
|
|
__FILE__, __LINE__, __func__, \ |
|
|
__VA_ARGS__) |
|
|
__VA_ARGS__) |
|
|
#define LOG_CRITICAL(log_class, ...) \ |
|
|
#define LOG_CRITICAL(log_class, ...) \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Critical, \ |
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Critical, \ |
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ |
|
|
|
|
|
|
|
|
__FILE__, __LINE__, __func__, \ |
|
|
__VA_ARGS__) |
|
|
__VA_ARGS__) |