mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 21:15:56 +08:00
Fix: switch Logger to truncating file sink with flush-on-trace
This commit is contained in:
1 parent
5023ecf90c
commit
998f4d139e
1 file changed
+6
-2
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user