Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log SDK errors to the console if the log level is fatal even if debug is disabled #1635

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Add http.request.method attribute to http spans data ([#1633](https://github.com/getsentry/sentry-dart/pull/1633))
- Add db.system and db.name attributes to db spans data ([#1629](https://github.com/getsentry/sentry-dart/pull/1629))
- 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))

### Features

Expand Down
4 changes: 3 additions & 1 deletion dart/lib/src/diagnostic_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class DiagnosticLogger {
}

bool _isEnabled(SentryLevel level) {
return _options.debug && level.ordinal >= _options.diagnosticLevel.ordinal;
return _options.debug &&
level.ordinal >= _options.diagnosticLevel.ordinal ||
level == SentryLevel.fatal;
}
}
64 changes: 64 additions & 0 deletions dart/test/diagnostic_logger_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:sentry/sentry.dart';
import 'package:sentry/src/diagnostic_logger.dart';
import 'package:test/test.dart';

void main() {
late Fixture fixture;

setUp(() {
fixture = Fixture();
});

test('$DiagnosticLogger do not log if debug is disabled', () {
fixture.options.debug = false;

fixture.getSut().log(SentryLevel.error, 'foobar');

expect(fixture.loggedMessage, isNull);
});

test('$DiagnosticLogger log if debug is enabled', () {
fixture.options.debug = true;

fixture.getSut().log(SentryLevel.error, 'foobar');

expect(fixture.loggedMessage, 'foobar');
});

test('$DiagnosticLogger do not log if level is too low', () {
fixture.options.debug = true;
fixture.options.diagnosticLevel = SentryLevel.error;

fixture.getSut().log(SentryLevel.warning, 'foobar');

expect(fixture.loggedMessage, isNull);
});

test('$DiagnosticLogger always log fatal', () {
fixture.options.debug = false;

fixture.getSut().log(SentryLevel.fatal, 'foobar');

expect(fixture.loggedMessage, 'foobar');
});
}

class Fixture {
var options = SentryOptions();

Object? loggedMessage;

DiagnosticLogger getSut() {
return DiagnosticLogger(mockLogger, options);
}

void mockLogger(
SentryLevel level,
String message, {
String? logger,
Object? exception,
StackTrace? stackTrace,
}) {
loggedMessage = message;
}
}
Loading