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.cpp128
1 files changed, 53 insertions, 75 deletions
diff --git a/src/zencore/sentryintegration.cpp b/src/zencore/sentryintegration.cpp
index bfff114c3..e39b8438d 100644
--- a/src/zencore/sentryintegration.cpp
+++ b/src/zencore/sentryintegration.cpp
@@ -4,29 +4,23 @@
#include <zencore/config.h>
#include <zencore/logging.h>
+#include <zencore/logging/registry.h>
+#include <zencore/logging/sink.h>
#include <zencore/session.h>
#include <zencore/uid.h>
#include <stdarg.h>
#include <stdio.h>
-#if ZEN_PLATFORM_LINUX
+#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
# include <pwd.h>
+# include <unistd.h>
#endif
-#if ZEN_PLATFORM_MAC
-# 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
# include <sentry.h>
-# include <spdlog/sinks/base_sink.h>
ZEN_THIRD_PARTY_INCLUDES_END
namespace sentry {
@@ -44,76 +38,58 @@ struct SentryAssertImpl : zen::AssertImpl
const zen::CallstackFrames* Callstack) override;
};
-class sentry_sink final : public spdlog::sinks::base_sink<spdlog::details::null_mutex>
+static constexpr sentry_level_t MapToSentryLevel[zen::logging::LogLevelCount] = {SENTRY_LEVEL_DEBUG,
+ SENTRY_LEVEL_DEBUG,
+ SENTRY_LEVEL_INFO,
+ SENTRY_LEVEL_WARNING,
+ SENTRY_LEVEL_ERROR,
+ SENTRY_LEVEL_FATAL,
+ SENTRY_LEVEL_DEBUG};
+
+class SentrySink final : public zen::logging::Sink
{
public:
- sentry_sink();
- ~sentry_sink();
+ SentrySink() = default;
+ ~SentrySink() = default;
+
+ void Log(const zen::logging::LogMessage& Msg) override
+ {
+ if (Msg.GetLevel() != zen::logging::Err && Msg.GetLevel() != zen::logging::Critical)
+ {
+ return;
+ }
+ try
+ {
+ std::string Message = fmt::format("{}\n{}({})", Msg.GetPayload(), Msg.GetSource().Filename, Msg.GetSource().Line);
+ sentry_value_t Event = sentry_value_new_message_event(
+ /* level */ MapToSentryLevel[Msg.GetLevel()],
+ /* logger */ nullptr,
+ /* message */ Message.c_str());
+ sentry_event_value_add_stacktrace(Event, NULL, 0);
+ sentry_capture_event(Event);
+ }
+ catch (const std::exception&)
+ {
+ // If our logging with Message formatting fails we do a non-allocating version and just post the payload raw
+ char TmpBuffer[256];
+ size_t MaxCopy = zen::Min<size_t>(Msg.GetPayload().size(), size_t(255));
+ memcpy(TmpBuffer, Msg.GetPayload().data(), MaxCopy);
+ TmpBuffer[MaxCopy] = '\0';
+ sentry_value_t Event = sentry_value_new_message_event(
+ /* level */ SENTRY_LEVEL_ERROR,
+ /* logger */ nullptr,
+ /* message */ TmpBuffer);
+ sentry_event_value_add_stacktrace(Event, NULL, 0);
+ sentry_capture_event(Event);
+ }
+ }
-protected:
- void sink_it_(const spdlog::details::log_msg& msg) override;
- void flush_() override;
+ void Flush() override {}
+ void SetFormatter(std::unique_ptr<zen::logging::Formatter>) override {}
};
//////////////////////////////////////////////////////////////////////////
-static constexpr sentry_level_t MapToSentryLevel[spdlog::level::level_enum::n_levels] = {SENTRY_LEVEL_DEBUG,
- SENTRY_LEVEL_DEBUG,
- SENTRY_LEVEL_INFO,
- SENTRY_LEVEL_WARNING,
- SENTRY_LEVEL_ERROR,
- SENTRY_LEVEL_FATAL,
- SENTRY_LEVEL_DEBUG};
-
-sentry_sink::sentry_sink()
-{
-}
-sentry_sink::~sentry_sink()
-{
-}
-
-void
-sentry_sink::sink_it_(const spdlog::details::log_msg& msg)
-{
- if (msg.level != spdlog::level::err && msg.level != spdlog::level::critical)
- {
- return;
- }
- try
- {
- auto MaybeNullString = [](const char* Ptr) { return Ptr ? Ptr : "<null>"; };
- std::string Message = fmt::format("{}\n{}({}) [{}]",
- msg.payload,
- MaybeNullString(msg.source.filename),
- msg.source.line,
- MaybeNullString(msg.source.funcname));
- sentry_value_t event = sentry_value_new_message_event(
- /* level */ MapToSentryLevel[msg.level],
- /* logger */ nullptr,
- /* message */ Message.c_str());
- sentry_event_value_add_stacktrace(event, NULL, 0);
- sentry_capture_event(event);
- }
- catch (const std::exception&)
- {
- // If our logging with Message formatting fails we do a non-allocating version and just post the msg.payload raw
- char TmpBuffer[256];
- size_t MaxCopy = zen::Min<size_t>(msg.payload.size(), size_t(255));
- memcpy(TmpBuffer, msg.payload.data(), MaxCopy);
- TmpBuffer[MaxCopy] = '\0';
- sentry_value_t event = sentry_value_new_message_event(
- /* level */ SENTRY_LEVEL_ERROR,
- /* logger */ nullptr,
- /* message */ TmpBuffer);
- sentry_event_value_add_stacktrace(event, NULL, 0);
- sentry_capture_event(event);
- }
-}
-void
-sentry_sink::flush_()
-{
-}
-
void
SentryAssertImpl::OnAssert(const char* Filename,
int LineNumber,
@@ -340,7 +316,9 @@ SentryIntegration::Initialize(const Config& Conf, const std::string& CommandLine
sentry_set_user(SentryUserObject);
- m_SentryLogger = spdlog::create<sentry::sentry_sink>("sentry");
+ logging::SinkPtr SentrySink(new sentry::SentrySink());
+ m_SentryLogger = Ref<logging::Logger>(new logging::Logger("sentry", std::vector<logging::SinkPtr>{SentrySink}));
+ logging::Registry::Instance().Register(m_SentryLogger);
logging::SetErrorLog("sentry");
m_SentryAssert = std::make_unique<sentry::SentryAssertImpl>();
@@ -354,7 +332,7 @@ SentryIntegration::LogStartupInformation()
{
// Initialize the sentry-sdk log category at Warn level to reduce startup noise.
// The level can be overridden via --log-debug=sentry-sdk or --log-info=sentry-sdk
- LogSentry.Logger().SetLogLevel(logging::level::Warn);
+ LogSentry.Logger().SetLogLevel(logging::Warn);
if (m_IsInitialized)
{