From 5a15eb4d94332d6e11847a4ae067e2ad69b4036b Mon Sep 17 00:00:00 2001 From: Niram7777 Date: Sat, 25 Apr 2026 16:19:30 +0200 Subject: [PATCH] Fix log async thread name and custom setting not loaded (#4319) * Log fix thread name in async * Log always load custom settings * Log always in color like before spdlog --- src/common/logging/log.cpp | 2 +- src/common/logging/log.h | 16 ++++++++-- src/common/logging/thread_name_formatter.h | 30 ------------------- src/emulator.cpp | 7 ++--- src/shader_recompiler/ir/microinstruction.cpp | 2 +- 5 files changed, 19 insertions(+), 38 deletions(-) diff --git a/src/common/logging/log.cpp b/src/common/logging/log.cpp index 9c5d1debb..511eda668 100644 --- a/src/common/logging/log.cpp +++ b/src/common/logging/log.cpp @@ -176,7 +176,7 @@ void Setup(std::string_view log_filename) { } #else - g_console_sink = UpdateColorLevels(std::make_shared()); + g_console_sink = UpdateColorLevels(std::make_shared(spdlog::color_mode::always)); #endif g_console_sink->set_formatter(std::make_unique(UNLIMITED_SIZE)); diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 1265cd4c3..e5aaae0ab 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -23,6 +23,7 @@ using spdlog_stdout = spdlog::sinks::stdout_color_sink_mt; #include "common/logging/classes.h" #include "common/path_util.h" +#include "common/thread.h" namespace Common::Log { extern bool g_should_append; @@ -33,13 +34,24 @@ void Setup(std::string_view log_filename); void Shutdown(); void Flush(); + +static constexpr std::array level_string_views{"Trace", "Debug", "Info", "Warning", + "Error", "Critical", "Off"}; + +[[nodiscard]] static constexpr std::string_view to_string_view(spdlog::level lvl) noexcept { + return level_string_views.at(level_to_number(lvl)); +} } // namespace Common::Log // Define the fmt lib macros -#define LOG_GENERIC(log_class, log_level, ...) \ +#define LOG_GENERIC(log_class, log_level, format, ...) \ do { \ if (auto logger = Common::Log::ALL_LOGGERS[log_class]) { \ - SPDLOG_LOGGER_CALL(logger, log_level, __VA_ARGS__); \ + logger->log(log_level, "[{}] <{}> ({}) {}:{} {}: " format, log_class, \ + Common::Log::to_string_view(log_level), Common::GetCurrentThreadName(), \ + spdlog::source_loc::basename(__FILE__), __LINE__, \ + std::string_view(__func__) == "operator()" ? "lambda" : __func__, \ + ##__VA_ARGS__); \ } \ } while (false) diff --git a/src/common/logging/thread_name_formatter.h b/src/common/logging/thread_name_formatter.h index 416795cfa..d57c69f67 100644 --- a/src/common/logging/thread_name_formatter.h +++ b/src/common/logging/thread_name_formatter.h @@ -9,18 +9,9 @@ #include #include -#include "common/thread.h" - namespace Common::Log { static constexpr unsigned long long UNLIMITED_SIZE = 0; -static constexpr std::array level_string_views{"Trace", "Debug", "Info", "Warning", - "Error", "Critical", "Off"}; - -[[nodiscard]] static constexpr std::string_view to_string_view(spdlog::level lvl) noexcept { - return level_string_views.at(level_to_number(lvl)); -} - struct thread_name_formatter : spdlog::formatter { ~thread_name_formatter() override = default; @@ -33,27 +24,6 @@ struct thread_name_formatter : spdlog::formatter { msg.color_range_start = dest.size(); - dest.push_back('['); - spdlog::details::fmt_helper::append_string_view(msg.logger_name, dest); - dest.push_back(']'); - dest.push_back(' '); - dest.push_back('<'); - spdlog::details::fmt_helper::append_string_view(Log::to_string_view(msg.log_level), dest); - dest.push_back('>'); - dest.push_back(' '); - dest.push_back('('); - spdlog::details::fmt_helper::append_string_view(GetCurrentThreadName(), dest); - dest.push_back(')'); - dest.push_back(' '); - spdlog::details::fmt_helper::append_string_view(msg.source.short_filename, dest); - dest.push_back(':'); - spdlog::details::fmt_helper::append_int(msg.source.line, dest); - dest.push_back(' '); - spdlog::details::fmt_helper::append_string_view( - std::string_view(msg.source.funcname) == "operator()" ? "lambda" : msg.source.funcname, - dest); - dest.push_back(':'); - dest.push_back(' '); spdlog::details::fmt_helper::append_string_view(msg.payload, dest); spdlog::details::fmt_helper::append_string_view(spdlog::details::os::default_eol, dest); diff --git a/src/emulator.cpp b/src/emulator.cpp index 6a4980c41..66fe154fa 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -243,11 +243,10 @@ void Emulator::Run(std::filesystem::path file, std::vector args, EmulatorSettings.Load(id); + Common::Log::Shutdown(); // Initialize logging as soon as possible - if (!id.empty() && EmulatorSettings.IsLogSeparate()) { - Common::Log::Shutdown(); - Common::Log::Setup(id + ".log"); - } + Common::Log::Setup((!id.empty() && EmulatorSettings.IsLogSeparate()) ? id + ".log" + : "shad_log.txt"); if (!std::filesystem::exists(file)) { LOG_CRITICAL(Loader, "eboot.bin does not exist: {}", diff --git a/src/shader_recompiler/ir/microinstruction.cpp b/src/shader_recompiler/ir/microinstruction.cpp index 837b9601e..11d86a9d5 100644 --- a/src/shader_recompiler/ir/microinstruction.cpp +++ b/src/shader_recompiler/ir/microinstruction.cpp @@ -169,7 +169,7 @@ Block* Inst::PhiBlock(size_t index) const { UNREACHABLE_MSG("{} is not a Phi instruction", op); } if (index >= phi_args.size()) { - UNREACHABLE_MSG("Out of bounds argument index {} in phi instruction"); + UNREACHABLE_MSG("Out of bounds argument index {} in phi instruction", index); } return phi_args[index].first; }