From 998f4d139ea2a25a36daa93554b0e06488a43e6d Mon Sep 17 00:00:00 2001 From: xiaozhou233 Date: Sat, 15 Aug 2026 11:42:15 +0800 Subject: [PATCH] Fix: switch Logger to truncating file sink with flush-on-trace --- includes/JuiceAgent/Logger.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/JuiceAgent/Logger.hpp b/includes/JuiceAgent/Logger.hpp index c59a34b..4ee2230 100644 --- a/includes/JuiceAgent/Logger.hpp +++ b/includes/JuiceAgent/Logger.hpp @@ -15,16 +15,15 @@ inline void init( spdlog::level::level_enum level = spdlog::level::trace ) { static bool initialized = false; + if (initialized) { spdlog::warn("Logger already initialized, skipping"); return; } - initialized = true; auto console_sink = std::make_shared(); - // truncate = true: overwrite the log file on startup auto file_sink = std::make_shared( file_name, @@ -50,6 +49,11 @@ inline void init( ); spdlog::set_default_logger(logger); + + // Flush after every log message + spdlog::flush_on(spdlog::level::trace); + + initialized = true; } } \ No newline at end of file