diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index 1f5340c123..cd685c4d40 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -154,7 +154,7 @@ LOG_CHANNEL(q_debug, "QDEBUG"); { utils::attach_console(utils::console_stream::std_err, true); - std::cerr << fmt::format("RPCS3: %s\n", text); + utils::output_stderr(fmt::format("RPCS3: %s\n", text)); #ifdef __linux__ jit_announce(0, 0, ""); #endif @@ -174,7 +174,7 @@ LOG_CHANNEL(q_debug, "QDEBUG"); } else { - std::cerr << fmt::format("RPCS3: %s\n", text); + utils::output_stderr(fmt::format("RPCS3: %s\n", text)); } static auto show_report = [is_html, include_help_text](std::string_view text) @@ -277,7 +277,7 @@ struct fatal_error_listener final : logs::listener utils::attach_console(utils::console_stream::std_err, false); // Output to error stream as is - std::cerr << _msg; + utils::output_stderr(_msg); #ifdef _WIN32 if (IsDebuggerPresent()) @@ -401,7 +401,7 @@ QCoreApplication* create_application(int& argc, char* argv[]) { const std::string msg = fmt::format("The command line value %s for %s is not allowed. Please use a valid value for Qt::HighDpiScaleFactorRoundingPolicy.", arg_val, arg_rounding); sys_log.error("%s", msg); // Don't exit with fatal error. The resulting dialog might be unreadable with dpi problems. - std::cerr << msg << std::endl; + utils::output_stderr(msg, true); } } } diff --git a/rpcs3/util/console.cpp b/rpcs3/util/console.cpp index fb75875ea4..e007c15c09 100644 --- a/rpcs3/util/console.cpp +++ b/rpcs3/util/console.cpp @@ -5,6 +5,8 @@ #include #endif +#include + namespace utils { void attach_console([[maybe_unused]] int stream, [[maybe_unused]] bool open_console) @@ -34,6 +36,26 @@ namespace utils { [[maybe_unused]] const auto con_in = freopen("CONIN$", "r", stdin); } +#endif + } + + void output_stderr(std::string_view str, bool with_endline) + { + if (with_endline) + { +#ifdef _WIN32 + std::clog << str; +#else + std::cerr << str; +#endif + str = "\n"; + } + +#ifdef _WIN32 + // Flush seems broken on Windows (deadlocks) + std::clog << str; +#else + std::cerr << str; #endif } } diff --git a/rpcs3/util/console.h b/rpcs3/util/console.h index 92b169a98f..717c85e811 100644 --- a/rpcs3/util/console.h +++ b/rpcs3/util/console.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace utils { enum console_stream @@ -10,4 +12,6 @@ namespace utils }; void attach_console(int stream, bool open_console); + + void output_stderr(std::string_view str, bool with_endline = false); }