2014-10-28 03:36:00 -04:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 00:38:14 -05:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-10-28 03:36:00 -04:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-09-30 16:11:47 -04:00
|
|
|
#include <algorithm>
|
|
|
|
#include <string_view>
|
|
|
|
|
2018-03-22 06:21:29 -04:00
|
|
|
#include <fmt/format.h>
|
2021-09-30 16:11:47 -04:00
|
|
|
|
2021-06-13 10:31:47 -04:00
|
|
|
#include "common/logging/types.h"
|
2014-10-28 03:36:00 -04:00
|
|
|
|
2021-04-14 20:19:52 -04:00
|
|
|
namespace Common::Log {
|
2014-10-28 03:36:00 -04:00
|
|
|
|
2019-12-24 15:19:18 -05:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2018-04-02 22:31:54 -04:00
|
|
|
/// Logs a message to the global logger, using fmt
|
2018-04-06 00:42:09 -04:00
|
|
|
void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
|
|
|
|
unsigned int line_num, const char* function, const char* format,
|
|
|
|
const fmt::format_args& args);
|
2018-04-02 22:31:54 -04:00
|
|
|
|
|
|
|
template <typename... Args>
|
2018-03-22 06:21:29 -04:00
|
|
|
void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num,
|
2018-04-02 22:31:54 -04:00
|
|
|
const char* function, const char* format, const Args&... args) {
|
2018-04-06 00:42:09 -04:00
|
|
|
FmtLogMessageImpl(log_class, log_level, filename, line_num, function, format,
|
2018-07-18 17:33:45 -04:00
|
|
|
fmt::make_format_args(args...));
|
2018-04-02 22:31:54 -04:00
|
|
|
}
|
2018-03-22 06:21:29 -04:00
|
|
|
|
2021-04-14 20:19:52 -04:00
|
|
|
} // namespace Common::Log
|
2014-10-28 03:36:00 -04:00
|
|
|
|
2018-03-22 06:21:29 -04:00
|
|
|
#ifdef _DEBUG
|
2018-07-02 12:13:26 -04:00
|
|
|
#define LOG_TRACE(log_class, ...) \
|
2021-04-14 20:19:52 -04:00
|
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Trace, \
|
|
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
|
|
|
|
__VA_ARGS__)
|
2018-03-22 06:21:29 -04:00
|
|
|
#else
|
2018-07-02 12:13:26 -04:00
|
|
|
#define LOG_TRACE(log_class, fmt, ...) (void(0))
|
2018-03-22 06:21:29 -04:00
|
|
|
#endif
|
|
|
|
|
2018-07-02 12:13:26 -04:00
|
|
|
#define LOG_DEBUG(log_class, ...) \
|
2021-04-14 20:19:52 -04:00
|
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Debug, \
|
|
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
|
|
|
|
__VA_ARGS__)
|
2018-07-02 12:13:26 -04:00
|
|
|
#define LOG_INFO(log_class, ...) \
|
2021-04-14 20:19:52 -04:00
|
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Info, \
|
|
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
|
|
|
|
__VA_ARGS__)
|
2018-07-02 12:13:26 -04:00
|
|
|
#define LOG_WARNING(log_class, ...) \
|
2021-04-14 20:19:52 -04:00
|
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Warning, \
|
|
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
|
|
|
|
__VA_ARGS__)
|
2018-07-02 12:13:26 -04:00
|
|
|
#define LOG_ERROR(log_class, ...) \
|
2021-04-14 20:19:52 -04:00
|
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Error, \
|
|
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
|
|
|
|
__VA_ARGS__)
|
2018-07-02 12:13:26 -04:00
|
|
|
#define LOG_CRITICAL(log_class, ...) \
|
2021-04-14 20:19:52 -04:00
|
|
|
Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Critical, \
|
|
|
|
Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
|
|
|
|
__VA_ARGS__)
|