Fix: switch Logger to truncating file sink with flush-on-trace

This commit is contained in:
xiaozhou233 committed 2026-08-15 11:42:15 +08:00
1 parent 5023ecf90c
commit 998f4d139e
1 file changed
+6 -2
+6 -2
View File
@@ -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<spdlog::sinks::stdout_color_sink_mt>();
// truncate = true: overwrite the log file on startup
auto file_sink =
std::make_shared<spdlog::sinks::basic_file_sink_mt>(
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;
}
}