simc / logger

Small, easy to use and extensible logger which prints beautiful logs.
https://pub.dev/packages/logger
MIT License
1.07k stars 129 forks source link

feat: Expose message, error, and stackTrace in OutputEvent #133

Closed percula closed 5 months ago

percula commented 2 years ago

This PR lays the groundwork for adding a FirebaseOutput (see below snippet), which I will be uploading as a separate package on pub.dev due to its dependency on Firebase Crashlytics. To be useful, Firebase needs the message, error, and stack trace, so this PR adds those to the OutputEvent. Once this is merged and released in logger, I'll know what version to use as the minimum version for the logger dependency in the FirebaseOutput package.

class FirebaseOutput extends LogOutput {
  List<Level> levels;

  FirebaseOutput({
    this.levels = const [Level.error],
  });

  @override
  void output(OutputEvent event) {
    if (levels.contains(event.level)) {
      FirebaseCrashlytics.instance.recordError(
          event.error,
          event.stackTrace,
          reason: event.message);
    }
  }

}
rd-martin-jaeger commented 2 years ago

Where do you get the error, stackTrace and message data from your OutputEvent? My class contains only two fields in version 1.1.0:

class OutputEvent {
  final Level level;
  final List<String> lines;

  OutputEvent(this.level, this.lines);
}
percula commented 2 years ago

Where do you get the error, stackTrace and message data from your OutputEvent? My class contains only two fields in version 1.1.0:

class OutputEvent {
  final Level level;
  final List<String> lines;

  OutputEvent(this.level, this.lines);
}

Yeah, unfortunately they're not included in OutputEvent, I had to add them as part of this PR.

0ttik commented 2 years ago

I strongly vote for this PR: this feature is important. Many log/crashlytics providers like sentry need typed data (ex. StackTrace, error reason, error object, etc.) which are lost when we are using only list of strings in LogOutput. I suggest we add something like origin = LogEvent() field to LogOutput to enable more granural outputs using Firebase/Sentry/other providers which needs access to fields of original event, but not the list of strings as it is now. Or use @percula's approach.

a1573595 commented 2 years ago

@leisim Please merge it. it is helpful.

percula commented 5 months ago

Closing as this appears to be implemented via OutputEvent.origin