aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/sentryintegration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore/sentryintegration.cpp')
-rw-r--r--src/zencore/sentryintegration.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/zencore/sentryintegration.cpp b/src/zencore/sentryintegration.cpp
index e39b8438d..8d087e8c6 100644
--- a/src/zencore/sentryintegration.cpp
+++ b/src/zencore/sentryintegration.cpp
@@ -128,6 +128,8 @@ namespace zen {
# if ZEN_USE_SENTRY
ZEN_DEFINE_LOG_CATEGORY_STATIC(LogSentry, "sentry-sdk");
+static std::atomic<bool> s_SentryLogEnabled{true};
+
static void
SentryLogFunction(sentry_level_t Level, const char* Message, va_list Args, [[maybe_unused]] void* Userdata)
{
@@ -147,14 +149,15 @@ SentryLogFunction(sentry_level_t Level, const char* Message, va_list Args, [[may
}
// SentryLogFunction can be called before the logging system is initialized
- // (during sentry_init which runs before InitializeLogging). Fall back to
- // console logging when the category logger is not yet available.
+ // (during sentry_init which runs before InitializeLogging), or after it has
+ // been shut down (during sentry_close on a background worker thread). Fall
+ // back to console logging when the category logger is not available.
//
// Since we want to default to WARN level but this runs before logging has
// been configured, we ignore the callbacks for DEBUG/INFO explicitly here
// which means users don't see every possible log message if they're trying
// to configure the levels using --log-debug=sentry-sdk
- if (!TheDefaultLogger)
+ if (!TheDefaultLogger || !s_SentryLogEnabled.load(std::memory_order_acquire))
{
switch (Level)
{
@@ -212,11 +215,21 @@ SentryIntegration::SentryIntegration()
SentryIntegration::~SentryIntegration()
{
+ Close();
+}
+
+void
+SentryIntegration::Close()
+{
if (m_IsInitialized && m_SentryErrorCode == 0)
{
logging::SetErrorLog("");
m_SentryAssert.reset();
+ // Disable spdlog forwarding before sentry_close() since its background
+ // worker thread may still log during shutdown via SentryLogFunction
+ s_SentryLogEnabled.store(false, std::memory_order_release);
sentry_close();
+ m_IsInitialized = false;
}
}