-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log SDK errors to the console if the log level is
fatal
even if `de…
…bug` is disabled (#1635)
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |