2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-03-07 08:35:01 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2009-03-07 08:35:01 +00:00
|
|
|
|
2020-11-19 01:51:56 +00:00
|
|
|
#include <cstddef>
|
2020-10-20 19:37:02 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
#include <string_view>
|
2020-11-19 01:51:56 +00:00
|
|
|
#include "Common/FormatUtil.h"
|
2020-10-20 19:37:02 +00:00
|
|
|
|
2019-11-28 09:19:24 +00:00
|
|
|
namespace Common::Log
|
2010-12-14 17:52:01 +00:00
|
|
|
{
|
2021-10-21 19:11:07 +00:00
|
|
|
enum class LogType : int
|
2013-10-19 22:58:02 +00:00
|
|
|
{
|
2009-03-07 08:35:01 +00:00
|
|
|
ACTIONREPLAY,
|
|
|
|
AUDIO,
|
|
|
|
AUDIO_INTERFACE,
|
|
|
|
BOOT,
|
|
|
|
COMMANDPROCESSOR,
|
|
|
|
COMMON,
|
|
|
|
CONSOLE,
|
2021-05-04 20:37:06 +00:00
|
|
|
CONTROLLERINTERFACE,
|
2017-03-01 14:15:42 +00:00
|
|
|
CORE,
|
2009-03-07 08:35:01 +00:00
|
|
|
DISCIO,
|
|
|
|
DSPHLE,
|
2009-04-06 17:12:05 +00:00
|
|
|
DSPLLE,
|
2009-07-18 01:16:17 +00:00
|
|
|
DSP_MAIL,
|
2009-03-07 08:35:01 +00:00
|
|
|
DSPINTERFACE,
|
|
|
|
DVDINTERFACE,
|
|
|
|
DYNA_REC,
|
|
|
|
EXPANSIONINTERFACE,
|
2015-09-10 06:28:44 +00:00
|
|
|
FILEMON,
|
2020-11-09 18:45:04 +00:00
|
|
|
FRAMEDUMP,
|
2013-01-06 10:28:27 +00:00
|
|
|
GDB_STUB,
|
2009-03-07 08:35:01 +00:00
|
|
|
GPFIFO,
|
2015-09-10 06:28:44 +00:00
|
|
|
HOST_GPU,
|
2017-01-18 19:38:44 +00:00
|
|
|
IOS,
|
|
|
|
IOS_DI,
|
|
|
|
IOS_ES,
|
2018-03-03 17:55:01 +00:00
|
|
|
IOS_FS,
|
2017-01-18 19:38:44 +00:00
|
|
|
IOS_NET,
|
|
|
|
IOS_SD,
|
|
|
|
IOS_SSL,
|
|
|
|
IOS_STM,
|
2017-01-18 21:32:22 +00:00
|
|
|
IOS_USB,
|
2017-01-18 19:38:44 +00:00
|
|
|
IOS_WC24,
|
2017-08-16 20:24:24 +00:00
|
|
|
IOS_WFS,
|
2017-01-18 19:38:44 +00:00
|
|
|
IOS_WIIMOTE,
|
2009-03-07 08:35:01 +00:00
|
|
|
MASTER_LOG,
|
|
|
|
MEMMAP,
|
2009-07-18 01:16:17 +00:00
|
|
|
MEMCARD_MANAGER,
|
2015-09-10 06:28:44 +00:00
|
|
|
NETPLAY,
|
|
|
|
OSHLE,
|
2009-03-07 08:35:01 +00:00
|
|
|
OSREPORT,
|
2020-12-25 05:38:59 +00:00
|
|
|
OSREPORT_HLE,
|
2009-03-07 08:35:01 +00:00
|
|
|
PIXELENGINE,
|
2015-09-10 06:28:44 +00:00
|
|
|
PROCESSORINTERFACE,
|
|
|
|
POWERPC,
|
2009-03-07 08:35:01 +00:00
|
|
|
SERIALINTERFACE,
|
2009-05-04 19:28:53 +00:00
|
|
|
SP1,
|
2018-03-22 07:18:25 +00:00
|
|
|
SYMBOLS,
|
2009-03-07 08:35:01 +00:00
|
|
|
VIDEO,
|
|
|
|
VIDEOINTERFACE,
|
|
|
|
WII_IPC,
|
2009-03-18 17:17:58 +00:00
|
|
|
WIIMOTE,
|
|
|
|
|
2009-03-07 08:35:01 +00:00
|
|
|
NUMBER_OF_LOGS // Must be last
|
|
|
|
};
|
|
|
|
|
2021-10-21 19:11:07 +00:00
|
|
|
enum class LogLevel : int
|
2013-10-19 22:58:02 +00:00
|
|
|
{
|
2014-08-22 00:11:52 +00:00
|
|
|
LNOTICE = 1, // VERY important information that is NOT errors. Like startup and OSReports.
|
|
|
|
LERROR = 2, // Critical errors
|
|
|
|
LWARNING = 3, // Something is suspicious.
|
|
|
|
LINFO = 4, // General information.
|
|
|
|
LDEBUG = 5, // Detailed debugging - might make things slow.
|
2009-03-07 08:35:01 +00:00
|
|
|
};
|
|
|
|
|
2021-10-15 19:45:27 +00:00
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
2021-10-21 19:11:07 +00:00
|
|
|
constexpr auto MAX_LOGLEVEL = Common::Log::LogLevel::LDEBUG;
|
2021-10-15 19:45:27 +00:00
|
|
|
#else
|
2021-10-21 19:11:07 +00:00
|
|
|
constexpr auto MAX_LOGLEVEL = Common::Log::LogLevel::LINFO;
|
2021-10-15 19:45:27 +00:00
|
|
|
#endif // logging
|
|
|
|
|
2014-02-08 01:23:34 +00:00
|
|
|
static const char LOG_LEVEL_TO_CHAR[7] = "-NEWID";
|
|
|
|
|
2021-10-21 19:11:07 +00:00
|
|
|
void GenericLogFmtImpl(LogLevel level, LogType type, const char* file, int line,
|
2020-11-19 01:36:36 +00:00
|
|
|
fmt::string_view format, const fmt::format_args& args);
|
2020-10-20 19:37:02 +00:00
|
|
|
|
2020-11-19 01:51:56 +00:00
|
|
|
template <std::size_t NumFields, typename S, typename... Args>
|
2021-10-21 19:11:07 +00:00
|
|
|
void GenericLogFmt(LogLevel level, LogType type, const char* file, int line, const S& format,
|
2020-11-19 01:36:36 +00:00
|
|
|
const Args&... args)
|
2020-10-20 19:37:02 +00:00
|
|
|
{
|
2020-11-19 01:51:56 +00:00
|
|
|
static_assert(NumFields == sizeof...(args),
|
|
|
|
"Unexpected number of replacement fields in format string; did you pass too few or "
|
|
|
|
"too many arguments?");
|
2020-11-19 01:36:36 +00:00
|
|
|
GenericLogFmtImpl(level, type, file, line, format,
|
|
|
|
fmt::make_args_checked<Args...>(format, args...));
|
2020-10-20 19:37:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-21 19:11:07 +00:00
|
|
|
void GenericLog(LogLevel level, LogType type, const char* file, int line, const char* fmt, ...)
|
2010-12-05 09:04:34 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
__attribute__((format(printf, 5, 6)))
|
|
|
|
#endif
|
|
|
|
;
|
2019-11-28 09:19:24 +00:00
|
|
|
} // namespace Common::Log
|
2009-03-07 08:35:01 +00:00
|
|
|
|
|
|
|
// Let the compiler optimize this out
|
2010-12-05 15:59:11 +00:00
|
|
|
#define GENERIC_LOG(t, v, ...) \
|
2018-04-16 16:08:16 +00:00
|
|
|
do \
|
2010-12-05 15:59:11 +00:00
|
|
|
{ \
|
2021-10-15 19:45:27 +00:00
|
|
|
if (v <= Common::Log::MAX_LOGLEVEL) \
|
2019-11-28 09:19:24 +00:00
|
|
|
Common::Log::GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \
|
2018-04-16 16:08:16 +00:00
|
|
|
} while (0)
|
2009-03-07 08:35:01 +00:00
|
|
|
|
2012-08-20 11:12:49 +00:00
|
|
|
#define ERROR_LOG(t, ...) \
|
|
|
|
do \
|
|
|
|
{ \
|
2021-10-21 19:11:07 +00:00
|
|
|
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LERROR, __VA_ARGS__); \
|
2012-08-20 11:12:49 +00:00
|
|
|
} while (0)
|
|
|
|
#define WARN_LOG(t, ...) \
|
|
|
|
do \
|
|
|
|
{ \
|
2021-10-21 19:11:07 +00:00
|
|
|
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LWARNING, __VA_ARGS__); \
|
2012-08-20 11:12:49 +00:00
|
|
|
} while (0)
|
|
|
|
#define NOTICE_LOG(t, ...) \
|
|
|
|
do \
|
|
|
|
{ \
|
2021-10-21 19:11:07 +00:00
|
|
|
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LNOTICE, __VA_ARGS__); \
|
2012-08-20 11:12:49 +00:00
|
|
|
} while (0)
|
|
|
|
#define INFO_LOG(t, ...) \
|
|
|
|
do \
|
|
|
|
{ \
|
2021-10-21 19:11:07 +00:00
|
|
|
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LINFO, __VA_ARGS__); \
|
2012-08-20 11:12:49 +00:00
|
|
|
} while (0)
|
|
|
|
#define DEBUG_LOG(t, ...) \
|
|
|
|
do \
|
|
|
|
{ \
|
2021-10-21 19:11:07 +00:00
|
|
|
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LDEBUG, __VA_ARGS__); \
|
2012-08-20 11:12:49 +00:00
|
|
|
} while (0)
|
2020-10-20 19:37:02 +00:00
|
|
|
|
|
|
|
// fmtlib capable API
|
|
|
|
|
2020-11-19 01:36:36 +00:00
|
|
|
#define GENERIC_LOG_FMT(t, v, format, ...) \
|
2020-10-20 19:37:02 +00:00
|
|
|
do \
|
|
|
|
{ \
|
2021-10-15 19:45:27 +00:00
|
|
|
if (v <= Common::Log::MAX_LOGLEVEL) \
|
2020-11-19 01:51:56 +00:00
|
|
|
{ \
|
|
|
|
/* Use a macro-like name to avoid shadowing warnings */ \
|
|
|
|
constexpr auto GENERIC_LOG_FMT_N = Common::CountFmtReplacementFields(format); \
|
|
|
|
Common::Log::GenericLogFmt<GENERIC_LOG_FMT_N>(v, t, __FILE__, __LINE__, FMT_STRING(format), \
|
|
|
|
##__VA_ARGS__); \
|
|
|
|
} \
|
2020-10-20 19:37:02 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ERROR_LOG_FMT(t, ...) \
|
|
|
|
do \
|
|
|
|
{ \
|
2021-10-21 19:11:07 +00:00
|
|
|
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LERROR, __VA_ARGS__); \
|
2020-10-20 19:37:02 +00:00
|
|
|
} while (0)
|
|
|
|
#define WARN_LOG_FMT(t, ...) \
|
|
|
|
do \
|
|
|
|
{ \
|
2021-10-21 19:11:07 +00:00
|
|
|
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LWARNING, __VA_ARGS__); \
|
2020-10-20 19:37:02 +00:00
|
|
|
} while (0)
|
|
|
|
#define NOTICE_LOG_FMT(t, ...) \
|
|
|
|
do \
|
|
|
|
{ \
|
2021-10-21 19:11:07 +00:00
|
|
|
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LNOTICE, __VA_ARGS__); \
|
2020-10-20 19:37:02 +00:00
|
|
|
} while (0)
|
|
|
|
#define INFO_LOG_FMT(t, ...) \
|
|
|
|
do \
|
|
|
|
{ \
|
2021-10-21 19:11:07 +00:00
|
|
|
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LINFO, __VA_ARGS__); \
|
2020-10-20 19:37:02 +00:00
|
|
|
} while (0)
|
|
|
|
#define DEBUG_LOG_FMT(t, ...) \
|
|
|
|
do \
|
|
|
|
{ \
|
2021-10-21 19:11:07 +00:00
|
|
|
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LDEBUG, __VA_ARGS__); \
|
2020-10-20 19:37:02 +00:00
|
|
|
} while (0)
|