| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <cstddef> |
| 7 |
#include <fmt/format.h> |
| 8 |
#include "Common/FormatUtil.h" |
| 9 |
|
| 10 |
namespace Common::Log |
| 11 |
{ |
| 12 |
enum class LogType : int |
| 13 |
{ |
| 14 |
ACHIEVEMENTS, |
| 15 |
ACTIONREPLAY, |
| 16 |
AUDIO, |
| 17 |
AUDIO_INTERFACE, |
| 18 |
BOOT, |
| 19 |
COMMANDPROCESSOR, |
| 20 |
COMMON, |
| 21 |
CONSOLE, |
| 22 |
CONTROLLERINTERFACE, |
| 23 |
CORE, |
| 24 |
DISCIO, |
| 25 |
DSPHLE, |
| 26 |
DSPLLE, |
| 27 |
DSP_MAIL, |
| 28 |
DSPINTERFACE, |
| 29 |
DVDINTERFACE, |
| 30 |
AMMEDIABOARD, |
| 31 |
AMMEDIABOARD_NET, |
| 32 |
DYNA_REC, |
| 33 |
EXPANSIONINTERFACE, |
| 34 |
FILEMON, |
| 35 |
FRAMEDUMP, |
| 36 |
GDB_STUB, |
| 37 |
GPFIFO, |
| 38 |
HOST_GPU, |
| 39 |
HSP, |
| 40 |
IOS, |
| 41 |
IOS_DI, |
| 42 |
IOS_ES, |
| 43 |
IOS_FS, |
| 44 |
IOS_NET, |
| 45 |
IOS_SD, |
| 46 |
IOS_SSL, |
| 47 |
IOS_STM, |
| 48 |
IOS_USB, |
| 49 |
IOS_WC24, |
| 50 |
IOS_WFS, |
| 51 |
IOS_WIIMOTE, |
| 52 |
MASTER_LOG, |
| 53 |
MEMMAP, |
| 54 |
MEMCARD_MANAGER, |
| 55 |
NETPLAY, |
| 56 |
OSHLE, |
| 57 |
OSREPORT, |
| 58 |
OSREPORT_HLE, |
| 59 |
PIXELENGINE, |
| 60 |
PROCESSORINTERFACE, |
| 61 |
POWERPC, |
| 62 |
SERIALINTERFACE, |
| 63 |
SERIALINTERFACE_AMBB, |
| 64 |
SERIALINTERFACE_CARD, |
| 65 |
SERIALINTERFACE_JVSIO, |
| 66 |
SP1, |
| 67 |
SYMBOLS, |
| 68 |
VIDEO, |
| 69 |
VIDEOINTERFACE, |
| 70 |
WII_IPC, |
| 71 |
WIIMOTE, |
| 72 |
|
| 73 |
NUMBER_OF_LOGS |
| 74 |
}; |
| 75 |
|
| 76 |
constexpr LogType LAST_LOG_TYPE = |
| 77 |
static_cast<LogType>(static_cast<int>(LogType::NUMBER_OF_LOGS) - 1); |
| 78 |
|
| 79 |
enum class LogLevel : int |
| 80 |
{ |
| 81 |
LNOTICE = 1, |
| 82 |
LERROR = 2, |
| 83 |
LWARNING = 3, |
| 84 |
LINFO = 4, |
| 85 |
LDEBUG = 5, |
| 86 |
}; |
| 87 |
|
| 88 |
#if defined(_DEBUG) || defined(DEBUGFAST) |
| 89 |
constexpr auto MAX_EFFECTIVE_LOGLEVEL = Common::Log::LogLevel::LDEBUG; |
| 90 |
#else |
| 91 |
constexpr auto MAX_EFFECTIVE_LOGLEVEL = Common::Log::LogLevel::LINFO; |
| 92 |
#endif |
| 93 |
|
| 94 |
static const char LOG_LEVEL_TO_CHAR[7] = "-NEWID"; |
| 95 |
|
| 96 |
void GenericLogFmtImpl(LogLevel level, LogType type, const char* file, int line, |
| 97 |
fmt::string_view format, const fmt::format_args& args); |
| 98 |
|
| 99 |
template <std::size_t NumFields, typename S, typename... Args> |
| 100 |
void GenericLogFmt(LogLevel level, LogType type, const char* file, int line, const S& format, |
| 101 |
const Args&... args) |
| 102 |
{ |
| 103 |
static_assert(NumFields == sizeof...(args), |
| 104 |
"Unexpected number of replacement fields in format string; did you pass too few or " |
| 105 |
"too many arguments?"); |
| 106 |
#if FMT_VERSION >= 110000 && FMT_VERSION < 120200 |
| 107 |
|
| 108 |
|
| 109 |
auto&& format_str = fmt::format_string<Args...>(format); |
| 110 |
#else |
| 111 |
auto&& format_str = format; |
| 112 |
#endif |
| 113 |
GenericLogFmtImpl(level, type, file, line, format_str, fmt::make_format_args(args...)); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
#define GENERIC_LOG_FMT(t, v, format, ...) \ |
| 120 |
do \ |
| 121 |
{ \ |
| 122 |
if (v <= Common::Log::MAX_EFFECTIVE_LOGLEVEL) \ |
| 123 |
{ \ |
| 124 |
\ |
| 125 |
constexpr auto GENERIC_LOG_FMT_N = Common::CountFmtReplacementFields(format); \ |
| 126 |
Common::Log::GenericLogFmt<GENERIC_LOG_FMT_N>( \ |
| 127 |
v, t, __FILE__, __LINE__, FMT_STRING(format) __VA_OPT__(, ) __VA_ARGS__); \ |
| 128 |
} \ |
| 129 |
} while (0) |
| 130 |
|
| 131 |
#define ERROR_LOG_FMT(t, ...) \ |
| 132 |
do \ |
| 133 |
{ \ |
| 134 |
GENERIC_LOG_FMT(Common::Log::LogType::t, \ |
| 135 |
Common::Log::LogLevel::LERROR __VA_OPT__(, ) __VA_ARGS__); \ |
| 136 |
} while (0) |
| 137 |
#define WARN_LOG_FMT(t, ...) \ |
| 138 |
do \ |
| 139 |
{ \ |
| 140 |
GENERIC_LOG_FMT(Common::Log::LogType::t, \ |
| 141 |
Common::Log::LogLevel::LWARNING __VA_OPT__(, ) __VA_ARGS__); \ |
| 142 |
} while (0) |
| 143 |
#define NOTICE_LOG_FMT(t, ...) \ |
| 144 |
do \ |
| 145 |
{ \ |
| 146 |
GENERIC_LOG_FMT(Common::Log::LogType::t, \ |
| 147 |
Common::Log::LogLevel::LNOTICE __VA_OPT__(, ) __VA_ARGS__); \ |
| 148 |
} while (0) |
| 149 |
#define INFO_LOG_FMT(t, ...) \ |
| 150 |
do \ |
| 151 |
{ \ |
| 152 |
GENERIC_LOG_FMT(Common::Log::LogType::t, \ |
| 153 |
Common::Log::LogLevel::LINFO __VA_OPT__(, ) __VA_ARGS__); \ |
| 154 |
} while (0) |
| 155 |
#define DEBUG_LOG_FMT(t, ...) \ |
| 156 |
do \ |
| 157 |
{ \ |
| 158 |
GENERIC_LOG_FMT(Common::Log::LogType::t, \ |
| 159 |
Common::Log::LogLevel::LDEBUG __VA_OPT__(, ) __VA_ARGS__); \ |
| 160 |
} while (0) |