Skip to content

Commit 5aa047a

Browse files
authored
Log SDK errors to the console if the log level is fatal even if debug is disabled (#1635)
1 parent 8fe0817 commit 5aa047a

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Add http.request.method attribute to http spans data ([#1633](https://github.com/getsentry/sentry-dart/pull/1633))
88
- Add db.system and db.name attributes to db spans data ([#1629](https://github.com/getsentry/sentry-dart/pull/1629))
9+
- Log SDK errors to the console if the log level is `fatal` even if `debug` is disabled ([#1635](https://github.com/getsentry/sentry-dart/pull/1635))
910

1011
### Features
1112

dart/lib/src/diagnostic_logger.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class DiagnosticLogger {
2626
}
2727

2828
bool _isEnabled(SentryLevel level) {
29-
return _options.debug && level.ordinal >= _options.diagnosticLevel.ordinal;
29+
return _options.debug &&
30+
level.ordinal >= _options.diagnosticLevel.ordinal ||
31+
level == SentryLevel.fatal;
3032
}
3133
}

dart/test/diagnostic_logger_test.dart

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'package:sentry/sentry.dart';
2+
import 'package:sentry/src/diagnostic_logger.dart';
3+
import 'package:test/test.dart';
4+
5+
void main() {
6+
late Fixture fixture;
7+
8+
setUp(() {
9+
fixture = Fixture();
10+
});
11+
12+
test('$DiagnosticLogger do not log if debug is disabled', () {
13+
fixture.options.debug = false;
14+
15+
fixture.getSut().log(SentryLevel.error, 'foobar');
16+
17+
expect(fixture.loggedMessage, isNull);
18+
});
19+
20+
test('$DiagnosticLogger log if debug is enabled', () {
21+
fixture.options.debug = true;
22+
23+
fixture.getSut().log(SentryLevel.error, 'foobar');
24+
25+
expect(fixture.loggedMessage, 'foobar');
26+
});
27+
28+
test('$DiagnosticLogger do not log if level is too low', () {
29+
fixture.options.debug = true;
30+
fixture.options.diagnosticLevel = SentryLevel.error;
31+
32+
fixture.getSut().log(SentryLevel.warning, 'foobar');
33+
34+
expect(fixture.loggedMessage, isNull);
35+
});
36+
37+
test('$DiagnosticLogger always log fatal', () {
38+
fixture.options.debug = false;
39+
40+
fixture.getSut().log(SentryLevel.fatal, 'foobar');
41+
42+
expect(fixture.loggedMessage, 'foobar');
43+
});
44+
}
45+
46+
class Fixture {
47+
var options = SentryOptions();
48+
49+
Object? loggedMessage;
50+
51+
DiagnosticLogger getSut() {
52+
return DiagnosticLogger(mockLogger, options);
53+
}
54+
55+
void mockLogger(
56+
SentryLevel level,
57+
String message, {
58+
String? logger,
59+
Object? exception,
60+
StackTrace? stackTrace,
61+
}) {
62+
loggedMessage = message;
63+
}
64+
}

0 commit comments

Comments
 (0)