Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
PR Feedback
  • Loading branch information
ueman committed Dec 1, 2021
commit 04c4fcc0fb6b75290e5ee132d42209ee86f7c40c
10 changes: 5 additions & 5 deletions logging/lib/src/logging_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import 'extension.dart';
class LoggingIntegration extends Integration<SentryOptions> {
/// Creates the [LoggingIntegration].
///
/// Setting [logExceptionAsEvent] to true (default) captures all
/// messages with errors as an [SentryEvent] instead of an [Breadcrumb].
/// Setting [logExceptionAsEvent] to false captures everything as
/// [Breadcrumb]s.
/// All log events equal or higher than [minBreadcrumbLevel] are recorded as a
/// [Breadcrumb].
/// All log events equal or higher than [minEventLevel] are recorded as a
/// [SentryEvent].
LoggingIntegration({
Level minBreadcrumbLevel = Level.INFO,
Level minEventLevel = Level.SEVERE,
Expand Down Expand Up @@ -56,7 +56,7 @@ class LoggingIntegration extends Integration<SentryOptions> {
}

bool _isLoggable(Level logLevel, Level minLevel) {
return logLevel > minLevel;
return logLevel >= minLevel;
}

void _onLog(LogRecord record) async {
Expand Down
37 changes: 31 additions & 6 deletions logging/test/logging_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ void main() {
await sut.call(fixture.hub, fixture.options);

final log = Logger('FooBarLogger');
log.warning(
'A log message',
);
log.warning('A log message');

expect(fixture.hub.events.length, 0);
expect(fixture.hub.breadcrumbs.length, 1);
Expand All @@ -58,14 +56,23 @@ void main() {
expect(crumb.type, 'debug');
});

test('logger gets recorded if level equal minlevel', () async {
final sut = fixture.createSut(minBreadcrumbLevel: Level.INFO);
await sut.call(fixture.hub, fixture.options);

final log = Logger('FooBarLogger');
log.info('A log message');

expect(fixture.hub.events.length, 0);
expect(fixture.hub.breadcrumbs.length, 1);
});

test('logger gets not recorded if level under minlevel', () async {
final sut = fixture.createSut(minBreadcrumbLevel: Level.SEVERE);
await sut.call(fixture.hub, fixture.options);

final log = Logger('FooBarLogger');
log.warning(
'A log message',
);
log.warning('A log message');

expect(fixture.hub.events.length, 0);
expect(fixture.hub.breadcrumbs.length, 0);
Expand Down Expand Up @@ -95,6 +102,24 @@ void main() {
expect(fixture.hub.events.first.stackTrace, stackTrace);
});

test('exception is recorded as event if minEventLevel equal minlevel',
() async {
final sut = fixture.createSut(minEventLevel: Level.INFO);
await sut.call(fixture.hub, fixture.options);

final exception = Exception('foo bar');
final stackTrace = StackTrace.current;

final log = Logger('FooBarLogger');
log.info(
'A log message',
exception,
stackTrace,
);
expect(fixture.hub.events.length, 1);
expect(fixture.hub.events.first.event.breadcrumbs, null);
});

test('exception is not recorded as event if minEventLevel under minlevel',
() async {
final sut = fixture.createSut(minEventLevel: Level.SEVERE);
Expand Down