From 478b2cc111c7b51e796255b4d5214fa20b128655 Mon Sep 17 00:00:00 2001 From: Jin Hai Date: Sun, 13 Oct 2024 23:47:08 +0800 Subject: [PATCH] Fix: flush log when unrecoverable error (#2030) ### What problem does this PR solve? spdlog might not flush the data when unrecoverable error raised. This PR is to fix it. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Signed-off-by: Jin Hai --- src/main/logger.cpp | 4 ++++ src/main/logger.cppm | 1 + 2 files changed, 5 insertions(+) diff --git a/src/main/logger.cpp b/src/main/logger.cpp index 43b7e9c2f4..586c0a0f97 100644 --- a/src/main/logger.cpp +++ b/src/main/logger.cpp @@ -89,6 +89,10 @@ void Logger::Initialize(const LoggerConfig &config) { SetLogLevel(config.log_level_); } +void Logger::Flush() { + infinity_logger->flush(); +} + void Logger::Shutdown() { if (stdout_sinker.get() != nullptr or rotating_file_sinker.get() != nullptr) { spdlog::shutdown(); diff --git a/src/main/logger.cppm b/src/main/logger.cppm index e66341a526..bbbca4d9e5 100644 --- a/src/main/logger.cppm +++ b/src/main/logger.cppm @@ -38,6 +38,7 @@ public: Initialize(Config* config_ptr); static void Initialize(const LoggerConfig &config); + static void Flush(); static void Shutdown();