-
-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathsentry_integration_qt.cpp
59 lines (50 loc) · 1.58 KB
/
sentry_integration_qt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "sentry_integration_qt.h"
#include "sentry_boot.h"
#include <QtCore/qglobal.h>
#include <QtCore/qstring.h>
static QtMessageHandler originalMessageHandler = nullptr;
static const char *
logLevelForMessageType(QtMsgType msgType)
{
switch (msgType) {
case QtDebugMsg:
return "debug";
case QtWarningMsg:
return "warning";
case QtCriticalMsg:
return "error";
case QtFatalMsg:
return "fatal";
case QtInfoMsg:
Q_FALLTHROUGH();
default:
return "info";
}
}
static void
sentry_qt_messsage_handler(
QtMsgType type, const QMessageLogContext &context, const QString &message)
{
sentry_value_t crumb
= sentry_value_new_breadcrumb("default", qUtf8Printable(message));
sentry_value_set_by_key(
crumb, "category", sentry_value_new_string(context.category));
sentry_value_set_by_key(
crumb, "level", sentry_value_new_string(logLevelForMessageType(type)));
sentry_value_t location = sentry_value_new_object();
sentry_value_set_by_key(
location, "file", sentry_value_new_string(context.file));
sentry_value_set_by_key(
location, "line", sentry_value_new_int32(context.line));
sentry_value_set_by_key(crumb, "data", location);
sentry_add_breadcrumb(crumb);
// Don't interfere with normal logging, by forwarding
// to any existing message handlers.
if (originalMessageHandler)
originalMessageHandler(type, context, message);
}
void
sentry_integration_setup_qt(void)
{
originalMessageHandler = qInstallMessageHandler(sentry_qt_messsage_handler);
}