Files
Ishiiruka/Source/Core/Common/Logging/Log.h

135 lines
4.5 KiB
C
Raw Normal View History

2015-05-25 18:36:28 -03:00
// Copyright 2009 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
2014-06-03 18:14:53 -03:00
#pragma once
namespace LogTypes
{
2014-09-03 17:38:59 -03:00
enum LOG_TYPE
{
ACTIONREPLAY,
AUDIO,
AUDIO_INTERFACE,
BOOT,
COMMANDPROCESSOR,
COMMON,
CONSOLE,
DISCIO,
DSPHLE,
DSPLLE,
DSP_MAIL,
DSPINTERFACE,
DVDINTERFACE,
DYNA_REC,
EXPANSIONINTERFACE,
2015-09-19 19:56:20 -03:00
FILEMON,
2014-09-03 17:38:59 -03:00
GDB_STUB,
GPFIFO,
2015-09-19 19:56:20 -03:00
HOST_GPU,
2014-09-03 17:38:59 -03:00
MASTER_LOG,
MEMMAP,
MEMCARD_MANAGER,
2015-09-19 19:56:20 -03:00
NETPLAY,
OSHLE,
2014-09-03 17:38:59 -03:00
OSREPORT,
PAD,
PIXELENGINE,
2015-09-19 19:56:20 -03:00
PROCESSORINTERFACE,
POWERPC,
2014-09-03 17:38:59 -03:00
SERIALINTERFACE,
2019-08-05 22:34:31 -07:00
SLIPPI,
2020-01-30 15:15:34 -08:00
SLIPPI_ONLINE,
2014-09-03 17:38:59 -03:00
SP1,
VIDEO,
VIDEOINTERFACE,
WII_IPC,
WII_IPC_DVD,
WII_IPC_ES,
WII_IPC_FILEIO,
WII_IPC_HID,
WII_IPC_HLE,
WII_IPC_NET,
WII_IPC_SD,
2015-09-19 19:56:20 -03:00
WII_IPC_SSL,
2014-09-03 17:38:59 -03:00
WII_IPC_STM,
2015-09-19 19:56:20 -03:00
WII_IPC_WC24,
2014-09-03 17:38:59 -03:00
WII_IPC_WIIMOTE,
WIIMOTE,
NUMBER_OF_LOGS // Must be last
2014-09-03 17:38:59 -03:00
};
enum LOG_LEVELS
{
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.
2014-09-03 17:38:59 -03:00
};
2014-09-03 17:38:59 -03:00
static const char LOG_LEVEL_TO_CHAR[7] = "-NEWID";
} // namespace
// Short File code taken from https://blog.galowicz.de/2016/02/20/short_file_macro/
2020-06-11 20:05:57 -07:00
static constexpr const char *past_last_slash(const char *str, const char * last_slash)
{
return *str == '\0' ? last_slash
: *str == '/' || *str == '\\' ? past_last_slash(str + 1, str + 1) : past_last_slash(str + 1, last_slash);
}
2020-06-11 20:05:57 -07:00
static constexpr const char *past_last_slash(const char * str)
{
return past_last_slash(str, str);
}
void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line,
const char* fmt, ...)
#ifdef __GNUC__
2016-07-08 16:14:35 -03:00
__attribute__((format(printf, 5, 6)))
#endif
2016-07-08 16:14:35 -03:00
;
#if defined LOGGING || defined _DEBUG || defined DEBUGFAST
2014-10-04 12:11:42 -03:00
#define MAX_LOGLEVEL LogTypes::LOG_LEVELS::LDEBUG
#else
#ifndef MAX_LOGLEVEL
#define MAX_LOGLEVEL LogTypes::LOG_LEVELS::LINFO
#endif // loglevel
#endif // logging
// Let the compiler optimize this out
#define GENERIC_LOG(t, v, ...) \
{ \
if (v <= MAX_LOGLEVEL) \
GenericLog(v, t, past_last_slash(__FILE__), __LINE__, __VA_ARGS__); \
}
#define ERROR_LOG(t, ...) \
do \
{ \
GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) \
} while (0)
#define WARN_LOG(t, ...) \
do \
{ \
GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) \
} while (0)
#define NOTICE_LOG(t, ...) \
do \
{ \
GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) \
} while (0)
#define INFO_LOG(t, ...) \
do \
{ \
GENERIC_LOG(LogTypes::t, LogTypes::LINFO, __VA_ARGS__) \
} while (0)
#define DEBUG_LOG(t, ...) \
do \
{ \
GENERIC_LOG(LogTypes::t, LogTypes::LDEBUG, __VA_ARGS__) \
} while (0)