fix(log): prevent sink destruction caused by backend exceptions (#4694)

This commit is contained in:
Yundi339
2026-02-10 22:13:56 +08:00
committed by GitHub
parent 97b6168ba6
commit e22c5c9e8e
+6
View File
@@ -15,6 +15,7 @@
#include <boost/log/expressions.hpp>
#include <boost/log/sinks.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/utility/exception_handler.hpp>
// 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);