base: logging: Add Linux support, add stderr output support

This commit is contained in:
Doug Johnson 2017-07-15 17:43:44 -06:00 committed by Sandy Carter
parent 2970b84bc1
commit e092c8c187
1 changed files with 9 additions and 4 deletions

View File

@ -29,14 +29,15 @@
// For MessageBox: // For MessageBox:
// TODO(benvanik): generic API? logging_win.cc? // TODO(benvanik): generic API? logging_win.cc?
// TODO(dougvj): For now I just inlined a small difference for linux
#if XE_PLATFORM_WIN32 #if XE_PLATFORM_WIN32
#include "xenia/base/platform_win.h" #include "xenia/base/platform_win.h"
#endif // XE_PLATFORM_WIN32 #endif // XE_PLATFORM_WIN32
DEFINE_string( DEFINE_string(log_file, "",
log_file, "", "Logs are written to the given file (specify stdout/stderr "
"Logs are written to the given file (specify stdout for command line)", "for command line)",
"Logging"); "Logging");
DEFINE_bool(log_to_debugprint, false, "Dump the log to DebugPrint.", "Logging"); DEFINE_bool(log_to_debugprint, false, "Dump the log to DebugPrint.", "Logging");
DEFINE_bool(flush_log, true, "Flush log file after each log line batch.", DEFINE_bool(flush_log, true, "Flush log file after each log line batch.",
"Logging"); "Logging");
@ -63,6 +64,8 @@ class Logger {
} else { } else {
if (cvars::log_file == "stdout") { if (cvars::log_file == "stdout") {
file_ = stdout; file_ = stdout;
} else if (cvars::log_file == "stderr") {
file_ = stderr;
} else { } else {
auto file_path = xe::to_wstring(cvars::log_file); auto file_path = xe::to_wstring(cvars::log_file);
xe::filesystem::CreateParentFolder(file_path); xe::filesystem::CreateParentFolder(file_path);
@ -330,6 +333,8 @@ void FatalError(const char* fmt, ...) {
MessageBoxA(NULL, log_format_buffer_.data(), "Xenia Error", MessageBoxA(NULL, log_format_buffer_.data(), "Xenia Error",
MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
} }
#elif XE_PLATFORM_LINUX
fprintf(stderr, fmt, args);
#endif // WIN32 #endif // WIN32
ShutdownLogging(); ShutdownLogging();
std::exit(1); std::exit(1);