Add log and change logger policy

This commit is contained in:
2026-04-25 20:29:58 +10:00
parent ef2a122fec
commit bab94bf9bc
2 changed files with 61 additions and 5 deletions

View File

@@ -163,7 +163,9 @@ namespace ANSCENTER
std::call_once(initFlag, [this]() {
try {
spdlog::init_thread_pool(8192, 1);
// Two worker threads so the slow Event Log sink (RPC to event log
// service) cannot starve the console sink. Queue size unchanged.
spdlog::init_thread_pool(8192, 2);
ConfigureLogger();
}
catch (const spdlog::spdlog_ex& ex) {
@@ -188,9 +190,14 @@ namespace ANSCENTER
stdout_sink->set_level(spdlog::level::trace);
consoleSinks.push_back(stdout_sink);
// overrun_oldest: producer never blocks. If the queue fills (8192
// pending msgs), the OLDEST queued msg is dropped to make room.
// Why: block + 1-thread pool + slow WindowsEventSink can stall
// inference threads on logging and, if shutdown races a blocked
// producer, surface as system_error("resource deadlock would occur").
auto consoleLogger = std::make_shared<spdlog::async_logger>(
"anslogger_console", consoleSinks.begin(), consoleSinks.end(),
spdlog::thread_pool(), spdlog::async_overflow_policy::block);
spdlog::thread_pool(), spdlog::async_overflow_policy::overrun_oldest);
consoleLogger->set_level(spdlog::level::trace);
consoleLogger->flush_on(spdlog::level::info);
spdlog::register_logger(consoleLogger);
@@ -201,9 +208,12 @@ namespace ANSCENTER
win_event_sink->set_level(spdlog::level::info);
std::vector<spdlog::sink_ptr> eventSinks{ win_event_sink };
// Same overrun_oldest policy as console — see note above. Especially
// important for this logger because WindowsEventSink::sink_it_ does
// a synchronous ReportEventW RPC which can be slow under load.
auto eventLogger = std::make_shared<spdlog::async_logger>(
"anslogger_event", eventSinks.begin(), eventSinks.end(),
spdlog::thread_pool(), spdlog::async_overflow_policy::block);
spdlog::thread_pool(), spdlog::async_overflow_policy::overrun_oldest);
eventLogger->set_level(spdlog::level::info);
eventLogger->flush_on(spdlog::level::info);
spdlog::register_logger(eventLogger);