diff --git a/CHANGELOG.md b/CHANGELOG.md index 815424836c..772782ec6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * Fix: `dist` was read from `SENTRY_DSN`, now it's read from `SENTRY_DIST` (#442) * Bump: sentry-cocoa to v7.0.3 (#445) * Fix: Fix adding integrations on web (#450) +* Fix: Use `log()` instead of `print()` for SDK logging (#453) # 5.0.0 diff --git a/dart/lib/src/protocol/sentry_level.dart b/dart/lib/src/protocol/sentry_level.dart index a0e59e32fc..a2524ce1ac 100644 --- a/dart/lib/src/protocol/sentry_level.dart +++ b/dart/lib/src/protocol/sentry_level.dart @@ -14,4 +14,30 @@ class SentryLevel { /// API name of the level as it is encoded in the JSON protocol. final String name; final int ordinal; + + /// For use with Dart's + /// [`log`](https://api.dart.dev/stable/2.12.4/dart-developer/log.html) + /// function. + /// These levels are inspired by + /// https://pub.dev/documentation/logging/latest/logging/Level-class.html + int toDartLogLevel() { + switch (this) { + // Level.SHOUT + case SentryLevel.fatal: + return 1200; + // Level.SEVERE + case SentryLevel.error: + return 1000; + // Level.SEVERE + case SentryLevel.warning: + return 900; + // Level.INFO + case SentryLevel.info: + return 800; + // Level.CONFIG + case SentryLevel.debug: + return 700; + } + return 700; + } } diff --git a/dart/lib/src/sentry_options.dart b/dart/lib/src/sentry_options.dart index c333887ee0..c2de293292 100644 --- a/dart/lib/src/sentry_options.dart +++ b/dart/lib/src/sentry_options.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:developer'; import 'package:http/http.dart'; @@ -254,5 +255,10 @@ void noOpLogger(SentryLevel level, String message) {} /// A Logger that prints out the level and message void dartLogger(SentryLevel level, String message) { - print('[${level.name}] $message'); + log( + '[${level.name}] $message', + level: level.toDartLogLevel(), + name: 'sentry', + time: getUtcDateTime(), + ); }