diff options
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | src/zenserver/diag/logging.cpp | 29 |
2 files changed, 31 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 505ca9f3b..76abe8640 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ ## +- Improvement: Ignore OOM errors in spdlog, just drop the error since we can't do anything useful if we run out of memory here +- Improvement: Try to catch any exceptions in spdlog error handling to avoid abort termination of process - Improvement: Block cache access/write log from writing to log if disk is low on free space ## 0.2.22 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(); |