Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Behavioral changes

- Set log level to `warning` by default when `debug = true` ([#2836](https://github.com/getsentry/sentry-dart/pull/2836))

### Dependencies

- Bump Android SDK from v8.2.0 to v8.6.0 ([#2819](https://github.com/getsentry/sentry-dart/pull/2819), [#2831](https://github.com/getsentry/sentry-dart/pull/2831))
Expand Down
3 changes: 2 additions & 1 deletion dart/lib/src/diagnostic_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import 'protocol.dart';
import 'sentry_options.dart';

class DiagnosticLogger {
final SentryLogger _logger;
final SentryOptions _options;
final SentryLogger _logger;
SentryLogger get logger => _logger;

DiagnosticLogger(this._logger, this._options);

Expand Down
20 changes: 13 additions & 7 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import 'version.dart';

/// Sentry SDK options
class SentryOptions {
/// Default Log level if not specified Default is DEBUG
static final SentryLevel _defaultDiagnosticLevel = SentryLevel.debug;
/// Default Log level if not specified Default is WARNING
static final SentryLevel _defaultDiagnosticLevel = SentryLevel.warning;

String? _dsn;
Dsn? _parsedDsn;
Expand Down Expand Up @@ -131,9 +131,13 @@ class SentryOptions {
SentryLogger get logger => _logger;

set logger(SentryLogger logger) {
_logger = DiagnosticLogger(logger, this).log;
diagnosticLogger = DiagnosticLogger(logger, this);
_logger = diagnosticLogger!.log;
}

@visibleForTesting
DiagnosticLogger? diagnosticLogger;

final List<EventProcessor> _eventProcessors = [];

/// Are callbacks that run for every event. They can either return a new event which in most cases
Expand All @@ -155,11 +159,13 @@ class SentryOptions {

set debug(bool newValue) {
_debug = newValue;
if (_debug == true && logger == noOpLogger) {
_logger = _debugLogger;
if (_debug == true &&
(logger == noOpLogger || diagnosticLogger?.logger == noOpLogger)) {
logger = _debugLogger;
}
if (_debug == false && logger == _debugLogger) {
_logger = noOpLogger;
if (_debug == false &&
(logger == _debugLogger || diagnosticLogger?.logger == _debugLogger)) {
logger = noOpLogger;
}
}

Expand Down
42 changes: 22 additions & 20 deletions dart/test/diagnostic_logger_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,39 @@ void main() {
fixture = Fixture();
});

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

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

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

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

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

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

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

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

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

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

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

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

Expand Down
6 changes: 6 additions & 0 deletions dart/test/sentry_options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ void main() {
expect(options.enableDartSymbolication, true);
});

test('diagnosticLevel is warning by default', () {
final options = defaultTestOptions();

expect(options.diagnosticLevel, SentryLevel.warning);
});

test('parsedDsn is correctly parsed and cached', () {
final options = defaultTestOptions();

Expand Down
9 changes: 6 additions & 3 deletions dart/test/sentry_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,18 @@ void main() {
(options) {
options.dsn = fakeDsn;
options.debug = true;
expect(options.logger, isNot(noOpLogger));
expect(options.diagnosticLogger?.logger, isNot(noOpLogger));

options.debug = false;
expect(options.logger, noOpLogger);
expect(options.diagnosticLogger?.logger, noOpLogger);

options.debug = true;
expect(options.diagnosticLogger?.logger, isNot(noOpLogger));
},
options: sentryOptions,
);

expect(sentryOptions.logger, noOpLogger);
expect(sentryOptions.diagnosticLogger?.logger, isNot(noOpLogger));
});

group('Sentry init optionsConfiguration', () {
Expand Down
1 change: 1 addition & 0 deletions flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Future<void> setupSentry(
// We can enable Sentry debug logging during development. This is likely
// going to log too much for your app, but can be useful when figuring out
// configuration issues, e.g. finding out why your events are not uploaded.
options.diagnosticLevel = SentryLevel.debug;
options.debug = kDebugMode;
options.spotlight = Spotlight(enabled: true);
options.enableTimeToFullDisplayTracing = true;
Expand Down
4 changes: 2 additions & 2 deletions flutter/lib/src/screenshot/recorder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'dart:async';
import 'dart:developer';
import 'dart:ui';

import 'package:flutter/cupertino.dart' as cupertino;
import 'package:flutter/material.dart' as material;
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart' as widgets;
import 'package:flutter/material.dart' as material;
import 'package:flutter/cupertino.dart' as cupertino;
import 'package:meta/meta.dart';

import '../../sentry_flutter.dart';
Expand Down
2 changes: 1 addition & 1 deletion flutter/test/integrations/init_native_sdk_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void main() {
{'name': 'pub:sentry_flutter', 'version': sdkVersion}
]
},
'diagnosticLevel': 'debug',
'diagnosticLevel': 'warning',
'maxBreadcrumbs': 100,
'anrEnabled': false,
'anrTimeoutIntervalMillis': 5000,
Expand Down
Loading