Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -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

Expand Down
26 changes: 26 additions & 0 deletions dart/lib/src/protocol/sentry_level.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 toLogLevel() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we call toDartLogLevel instead?

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 1200;
Comment thread
ueman marked this conversation as resolved.
Outdated
}
}
8 changes: 7 additions & 1 deletion dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:developer';

import 'package:http/http.dart';

Expand Down Expand Up @@ -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) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For v6 I'd like to add an error and stacktrace parameter to our loggers.

They can be passed to https://api.flutter.dev/flutter/dart-developer/log.html and look hopefully better

print('[${level.name}] $message');
log(
'[${level.name}] $message',
level: level.toLogLevel(),
name: 'sentry',
time: getUtcDateTime(),
);
}