From 5329c4024b862b1f748e334a1a72c21702e7fcd3 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 18 Sep 2020 10:34:40 +0100 Subject: [PATCH] Sentry experiment: record warnings/alerts This means that when a crash/exception occurs, we can see the preceding warnings and alerts. Not sure if this will really help, so giving it a test. --- src/Main/sentryIntegration.cxx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Main/sentryIntegration.cxx b/src/Main/sentryIntegration.cxx index 2a3cda173..8060a771c 100644 --- a/src/Main/sentryIntegration.cxx +++ b/src/Main/sentryIntegration.cxx @@ -20,6 +20,7 @@ #include "sentryIntegration.hxx" +#include #include #include #include @@ -40,6 +41,31 @@ static bool static_sentryEnabled = false; #include +namespace { + +class SentryLogCallback : public simgear::LogCallback +{ +public: + SentryLogCallback() : simgear::LogCallback(SG_ALL, SG_WARN) + { + } + + bool doProcessEntry(const simgear::LogEntry& e) override + { + // we need original priority here, so we don't record MANDATORY_INFO + // or DEV_ messages, which would get noisy. + const auto op = e.originalPriority; + if ((op != SG_WARN) && (op != SG_ALERT)) { + return true; + } + + flightgear::addSentryBreadcrumb(e.message, (op == SG_WARN) ? "warning" : "error"); + return true; + } +}; + +} // namespace + namespace flightgear { @@ -100,6 +126,8 @@ void initSentry() sentry_init(options); static_sentryEnabled = true; + + sglog().addCallback(new SentryLogCallback); } void delayedSentryInit()