Move EmuLog(Ex) together with the other logging functions

This commit is contained in:
ergo720 2019-04-21 14:27:23 +02:00
parent c917ff0d47
commit 884cef91e9
4 changed files with 63 additions and 63 deletions

View File

@ -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()
{

View File

@ -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();

View File

@ -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];

View File

@ -30,12 +30,7 @@
#undef FIELD_OFFSET // prevent macro redefinition warnings
#include <windows.h>
#include <multimon.h>
// 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 <multimon.h>
std::string FormatTitleId(uint32_t title_id);