From 884cef91e94576b29c9d8eea871436d7a7acf21a Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Sun, 21 Apr 2019 14:27:23 +0200 Subject: [PATCH] Move EmuLog(Ex) together with the other logging functions --- src/common/Logging.cpp | 56 +++++++++++++++++++++++++++++++ src/common/Logging.h | 5 +++ src/core/kernel/support/Emu.cpp | 58 +-------------------------------- src/core/kernel/support/Emu.h | 7 +--- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/common/Logging.cpp b/src/common/Logging.cpp index 4044b2cf6..4468c09b4 100644 --- a/src/common/Logging.cpp +++ b/src/common/Logging.cpp @@ -97,6 +97,62 @@ const char* g_EnumModules2String[to_underlying(CXBXR_MODULE::MAX)] = { }; std::atomic_int g_CurrentLogLevel = to_underlying(LOG_LEVEL::INFO); +const char log_debug[] = "DEBUG: "; +const char log_info[] = "INFO : "; +const char log_warn[] = "WARN : "; +const char log_fatal[] = "FATAL: "; +const char log_unkwn[] = "???? : "; + +// print out a warning message to the kernel debug log file +void NTAPI EmuLogEx(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, const char *szWarningMessage, ...) +{ + if (szWarningMessage == NULL) { + return; + } + + LOG_CHECK_ENABLED_EX(cxbxr_module, level) { + if (g_bPrintfOn) { + + va_list argp; + const char* level_str; + + LOG_THREAD_INIT; + + switch (level) { + default: + level_str = log_unkwn; + break; + case LOG_LEVEL::DEBUG: + level_str = log_debug; + break; + case LOG_LEVEL::INFO: + level_str = log_info; + break; + case LOG_LEVEL::WARNING: + level_str = log_warn; + break; + case LOG_LEVEL::FATAL: + level_str = log_fatal; + break; + } + + std::cout << _logThreadPrefix << level_str + << g_EnumModules2String[to_underlying(cxbxr_module)]; + + va_start(argp, szWarningMessage); + + vfprintf(stdout, szWarningMessage, argp); + + va_end(argp); + + fprintf(stdout, "\n"); + + fflush(stdout); + + } + } +} + // Set up the logging variables for the GUI process inline void log_get_settings() { diff --git a/src/common/Logging.h b/src/common/Logging.h index aaa4592be..7a80d6b25 100644 --- a/src/common/Logging.h +++ b/src/common/Logging.h @@ -109,6 +109,11 @@ typedef enum class _CXBXR_MODULE: unsigned int { extern std::atomic_bool g_EnabledModules[to_underlying(CXBXR_MODULE::MAX)]; extern const char* g_EnumModules2String[to_underlying(CXBXR_MODULE::MAX)]; extern std::atomic_int g_CurrentLogLevel; + +// print out a log message to the kernel debug log file if level is high enough +void NTAPI EmuLogEx(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, const char *szWarningMessage, ...); + +#define EmuLog(level, fmt, ...) EmuLogEx(LOG_PREFIX, level, fmt, ##__VA_ARGS__) extern inline void log_get_settings(); diff --git a/src/core/kernel/support/Emu.cpp b/src/core/kernel/support/Emu.cpp index 134dd796b..ed5ae6f54 100644 --- a/src/core/kernel/support/Emu.cpp +++ b/src/core/kernel/support/Emu.cpp @@ -56,13 +56,7 @@ bool g_DisablePixelShaders = false; bool g_UseAllCores = false; bool g_SkipRdtscPatching = false; bool g_ScaleViewport = false; -bool g_DirectHostBackBufferAccess = false; - -const char log_debug[] = "DEBUG: "; -const char log_info[] = "INFO : "; -const char log_warn[] = "WARN : "; -const char log_fatal[] = "FATAL: "; -const char log_unkwn[] = "???? : "; +bool g_DirectHostBackBufferAccess = false; // Delta added to host SystemTime, used in KiClockIsr and KeSetSystemTime // This shouldn't need to be atomic, but because raising the IRQL to high lv in KeSetSystemTime doesn't really stop KiClockIsr from running, @@ -99,56 +93,6 @@ std::string FormatTitleId(uint32_t title_id) return ss.str(); } -// print out a warning message to the kernel debug log file -void NTAPI EmuLogEx(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, const char *szWarningMessage, ...) -{ - if (szWarningMessage == NULL) { - return; - } - - LOG_CHECK_ENABLED_EX(cxbxr_module, level) { - if (g_bPrintfOn) { - - va_list argp; - const char* level_str; - - LOG_THREAD_INIT; - - switch (level) { - default: - level_str = log_unkwn; - break; - case LOG_LEVEL::DEBUG: - level_str = log_debug; - break; - case LOG_LEVEL::INFO: - level_str = log_info; - break; - case LOG_LEVEL::WARNING: - level_str = log_warn; - break; - case LOG_LEVEL::FATAL: - level_str = log_fatal; - break; - } - - std::cout << _logThreadPrefix << level_str - << g_EnumModules2String[to_underlying(cxbxr_module)]; - - va_start(argp, szWarningMessage); - - vfprintf(stdout, szWarningMessage, argp); - - va_end(argp); - - fprintf(stdout, "\n"); - - fflush(stdout); - - } - } -} - std::string EIPToString(xbaddr EIP) { char buffer[256]; diff --git a/src/core/kernel/support/Emu.h b/src/core/kernel/support/Emu.h index 74f7300b5..63b101c4c 100644 --- a/src/core/kernel/support/Emu.h +++ b/src/core/kernel/support/Emu.h @@ -30,12 +30,7 @@ #undef FIELD_OFFSET // prevent macro redefinition warnings #include -#include - -// print out a log message to the kernel debug log file if level is high enough -void NTAPI EmuLogEx(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, const char *szWarningMessage, ...); - -#define EmuLog(level, fmt, ...) EmuLogEx(LOG_PREFIX, level, fmt, ##__VA_ARGS__) +#include std::string FormatTitleId(uint32_t title_id);