From cc03c189dc4684dc870d6d17a98bc98cd1deb7b9 Mon Sep 17 00:00:00 2001 From: Cynthia Date: Sun, 21 Jun 2026 10:58:38 -0700 Subject: [PATCH] update console logging to using fwrite --- src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp | 15 ++++++++++----- src/config/LaunchSettings.cpp | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp b/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp index 1b34d8bf..d25809da 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp @@ -554,14 +554,19 @@ namespace coreinit std::unique_lock _l(sCafeConsoleMutex); CafeLogBuffer& logBuffer = getLogBuffer(cafeLogType); // once a line is full or \n is written it will be posted to log - auto flushLine = [](CafeLogBuffer& cafeLogBuffer, std::string_view cafeLogName, bool forwardToConsole) -> void + auto flushLine = [](CafeLogBuffer& cafeLogBuffer, std::string_view cafeLogName) -> void { cemuLog_log(LogType::CoreinitLogging, "[{0}] {1}", cafeLogName, std::basic_string_view(cafeLogBuffer.lineBuffer.data(), cafeLogBuffer.lineLength)); - if (forwardToConsole) - std::cerr << fmt::format("{0}\n", std::basic_string_view(cafeLogBuffer.lineBuffer.data(), cafeLogBuffer.lineLength)); cafeLogBuffer.lineLength = 0; }; + if (s_forwardConsoleLogs) { + if (cafeLogType == CafeLogType::OSCONSOLE) { + fwrite(msg, 1, len, stdout); + } else { + fwrite(msg, 1, len, stderr); + } + } while (len) { char c = *msg; @@ -572,13 +577,13 @@ namespace coreinit if (c == '\n') { // flush line immediately - flushLine(logBuffer, getLogBufferName(cafeLogType), s_forwardConsoleLogs); + flushLine(logBuffer, getLogBufferName(cafeLogType)); continue; } logBuffer.lineBuffer[logBuffer.lineLength] = c; logBuffer.lineLength++; if (logBuffer.lineLength >= logBuffer.lineBuffer.size()) - flushLine(logBuffer, getLogBufferName(cafeLogType), s_forwardConsoleLogs); + flushLine(logBuffer, getLogBufferName(cafeLogType)); } } diff --git a/src/config/LaunchSettings.cpp b/src/config/LaunchSettings.cpp index babd2c65..10aec810 100644 --- a/src/config/LaunchSettings.cpp +++ b/src/config/LaunchSettings.cpp @@ -72,7 +72,7 @@ bool LaunchSettings::HandleCommandline(const std::vector& args) ("account,a", po::value(), "Persistent id of account") ("extra-mounts", po::wvalue>()->composing(), "A series of mounts in the form of: (path on host:path within emulated system, e.g. `/tmp:/vol/temporary/`)") - ("forward-console-logging", "Forward OSReport, OSConsoleWrite, etc. to stderr.") + ("forward-console-logging", "Forward OSReport, OSConsoleWrite, etc. to stdout/stderr.") ("standalone-title-arguments", po::value(), "Custom arguments to pass as arguments to a standalone RPX that is launched.") ("force-interpreter", po::value()->implicit_value(true), "Force interpreter CPU emulation, disables recompiler. Useful for debugging purposes where you want to get accurate memory accesses and stack traces.")