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