Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Replace print() with log() #453

Merged
merged 7 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 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;
}
}
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
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.toDartLogLevel(),
name: 'sentry',
time: getUtcDateTime(),
);
}