From 2b7d54f785c936706809a802b10f5bfb0d2759ad Mon Sep 17 00:00:00 2001 From: Niram7777 Date: Tue, 21 Apr 2026 22:24:05 +0200 Subject: [PATCH] Dont use logger after Shutdown (#4302) * Only flush log if not Shutdown * Fix null logger deref, copy it --- src/common/logging/log.cpp | 9 +++++++-- src/common/logging/log.h | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/common/logging/log.cpp b/src/common/logging/log.cpp index 3484cfe3a..9c5d1debb 100644 --- a/src/common/logging/log.cpp +++ b/src/common/logging/log.cpp @@ -242,7 +242,12 @@ void Shutdown() { } void Flush() { - g_shad_file_sink->flush(); - g_console_sink->flush(); + if (g_shad_file_sink != nullptr) { + g_shad_file_sink->flush(); + } + + if (g_console_sink != nullptr) { + g_console_sink->flush(); + } } } // namespace Common::Log diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 6664bc684..1265cd4c3 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -37,7 +37,11 @@ void Flush(); // Define the fmt lib macros #define LOG_GENERIC(log_class, log_level, ...) \ - SPDLOG_LOGGER_CALL(Common::Log::ALL_LOGGERS[log_class], log_level, __VA_ARGS__) + do { \ + if (auto logger = Common::Log::ALL_LOGGERS[log_class]) { \ + SPDLOG_LOGGER_CALL(logger, log_level, __VA_ARGS__); \ + } \ + } while (false) #ifdef _DEBUG #define LOG_TRACE(log_class, ...) \