From e22c5c9e8e9823bda2c3b87d5a90b5e486fd08c8 Mon Sep 17 00:00:00 2001 From: Yundi339 Date: Tue, 10 Feb 2026 22:13:56 +0800 Subject: [PATCH] fix(log): prevent sink destruction caused by backend exceptions (#4694) --- src/logging.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/logging.cpp b/src/logging.cpp index d52e255b..d360d6af 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -15,6 +15,7 @@ #include #include #include +#include // local includes #include "logging.h" @@ -168,6 +169,11 @@ namespace logging { sink->set_filter(severity >= min_log_level); sink->set_formatter(&formatter); + // Prevent the async sink's background thread from dying on backend exceptions. + // Without this, a single I/O error (disk full, file locked, broken stdout, etc.) + // kills the thread and all subsequent log records are silently lost. + sink->set_exception_handler(bl::make_exception_suppressor()); + // Flush after each log record to ensure log file contents on disk isn't stale. // This is particularly important when running from a Windows service. sink->locked_backend()->auto_flush(true);