diff options
| author | Dan Engelbrecht <[email protected]> | 2023-09-19 05:03:54 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-19 11:03:54 +0200 |
| commit | 0da54c8f3ad4aa6d2f3e9eac3ff1a77f07d19fb7 (patch) | |
| tree | 6946629458686541a5913888583157388984e620 /src | |
| parent | add DiskWriteBlocker to structured cache store log writer (#408) (diff) | |
| download | zen-0da54c8f3ad4aa6d2f3e9eac3ff1a77f07d19fb7.tar.xz zen-0da54c8f3ad4aa6d2f3e9eac3ff1a77f07d19fb7.zip | |
handle errors in spdlog gracefully (#410)
* handle errors in spdlog gracefully - try to report and avoid termination
* changelog
Diffstat (limited to 'src')
| -rw-r--r-- | src/zenserver/diag/logging.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/zenserver/diag/logging.cpp b/src/zenserver/diag/logging.cpp index 13270b41d..0f15253cc 100644 --- a/src/zenserver/diag/logging.cpp +++ b/src/zenserver/diag/logging.cpp @@ -446,6 +446,35 @@ InitializeLogging(const ZenServerOptions& GlobalOptions) FileSink->set_pattern("[%C-%m-%d.%e %T] [%n] [%l] %v"); } + spdlog::set_error_handler([](const std::string& msg) { + if (msg == std::bad_alloc().what()) + { + // Don't report out of memory in spdlog as we usually log in response to errors which will cause another OOM crashing the + // program + return; + } + // Bypass zen logging wrapping to reduce potential other error sources + if (auto ErrLogger = zen::logging::ErrorLog(); ErrLogger != nullptr) + { + try + { + ErrLogger->log(spdlog::level::err, msg); + } + catch (const std::exception&) + { + // Just ignore any errors when in error handler + } + } + try + { + Log().error(msg); + } + catch (const std::exception&) + { + // Just ignore any errors when in error handler + } + }); + const std::string StartLogTime = zen::DateTime::Now().ToIso8601(); const zen::Oid ServerSessionId = zen::GetSessionId(); |