diff options
| author | Stefan Boberg <[email protected]> | 2023-11-06 20:36:30 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-06 20:36:30 +0100 |
| commit | 07f288d6e119fc6bb524fb634bc9094109a2ab05 (patch) | |
| tree | 8531bd38d0d8c3567ba3d0a5603f549faf99632b /src/zenserver/sentryintegration.cpp | |
| parent | gc v2 tests (#512) (diff) | |
| download | zen-07f288d6e119fc6bb524fb634bc9094109a2ab05.tar.xz zen-07f288d6e119fc6bb524fb634bc9094109a2ab05.zip | |
spdlog implementation hiding (#498)
this change aims to hide logging internals from client code, in order to make it easier to extend and take more control over the logging process in the future.
As a bonus side effect, the generated code is much tighter (net delta around 2.5% on the resulting executable which includes lots of thirdparty code) and should take less time to compile and link.
Client usage via macros is pretty much unchanged. The main exposure client code had to spdlog internals before was the use of custom loggers per subsystem, where it would be common to have `spdlog::logger` references to keep a reference to a logger within a class. This is now replaced by `zen::LoggerRef` which currently simply encapsulates an actual `spdlog::logger` instance, but this is intended to be an implementation detail which will change in the future.
The way the change works is that we now handle any formatting of log messages in the zencore logging subsystem instead of relying on `spdlog` to manage this. We use the `fmt` library to do the formatting which means the client usage is identical to using `spdlog`. The formatted message is then forwarded onto any sinks etc which are still implememted via `spdlog`.
Diffstat (limited to 'src/zenserver/sentryintegration.cpp')
| -rw-r--r-- | src/zenserver/sentryintegration.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/zenserver/sentryintegration.cpp b/src/zenserver/sentryintegration.cpp index 10a05c3c8..755fe97db 100644 --- a/src/zenserver/sentryintegration.cpp +++ b/src/zenserver/sentryintegration.cpp @@ -16,6 +16,10 @@ # include <pwd.h> #endif +ZEN_THIRD_PARTY_INCLUDES_START +#include <spdlog/spdlog.h> +ZEN_THIRD_PARTY_INCLUDES_END + #if ZEN_USE_SENTRY # define SENTRY_BUILD_STATIC 1 ZEN_THIRD_PARTY_INCLUDES_START @@ -162,23 +166,23 @@ SentryLogFunction(sentry_level_t Level, const char* Message, va_list Args, [[may switch (Level) { case SENTRY_LEVEL_DEBUG: - ConsoleLog().debug("sentry: {}", MessagePtr); + ZEN_CONSOLE_DEBUG("sentry: {}", MessagePtr); break; case SENTRY_LEVEL_INFO: - ConsoleLog().info("sentry: {}", MessagePtr); + ZEN_CONSOLE_INFO("sentry: {}", MessagePtr); break; case SENTRY_LEVEL_WARNING: - ConsoleLog().warn("sentry: {}", MessagePtr); + ZEN_CONSOLE_WARN("sentry: {}", MessagePtr); break; case SENTRY_LEVEL_ERROR: - ConsoleLog().error("sentry: {}", MessagePtr); + ZEN_CONSOLE_ERROR("sentry: {}", MessagePtr); break; case SENTRY_LEVEL_FATAL: - ConsoleLog().critical("sentry: {}", MessagePtr); + ZEN_CONSOLE_CRITICAL("sentry: {}", MessagePtr); break; } } @@ -192,7 +196,7 @@ SentryIntegration::~SentryIntegration() { if (m_IsInitialized && m_SentryErrorCode == 0) { - logging::SetErrorLog(std::shared_ptr<spdlog::logger>()); + logging::SetErrorLog(""); m_SentryAssert.reset(); sentry_close(); } @@ -250,8 +254,8 @@ SentryIntegration::Initialize(std::string SentryDatabasePath, std::string Sentry sentry_set_user(SentryUserObject); } - auto SentrySink = spdlog::create<sentry::sentry_sink>("sentry"); - logging::SetErrorLog(std::move(SentrySink)); + m_SentryLogger = spdlog::create<sentry::sentry_sink>("sentry"); + logging::SetErrorLog("sentry"); m_SentryAssert = std::make_unique<sentry::SentryAssertImpl>(); } |