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

[Questions] - How to send error level logs in crashlytics ? #138

Open kristijorgji opened 2 years ago

kristijorgji commented 2 years ago

Hi, I would like to know if it is possible and how to implement this fucntionality:

Every time I use logger.e for error level, I would like the logger to send this information in crashlytics so I can get report about it. Right now I don't get any information about logger.e when app is in production env and in clients devices.

I can see console output only when I develop

Desync-o-tron commented 2 years ago

I too am interested see documentation added for how I can send my logs to sentry.io

Desync-o-tron commented 2 years ago

It looks like we can use the LogOutput class to send events to a network target.

haroonkhan9426 commented 2 years ago

Here it’s also mentioned in the official docs that you can log events anywhere e.g file, firebase or logcat etc. I hope it helps.

Screenshot 2022-06-19 at 2 52 03 PM
ayberkcal commented 1 year ago

I've using different approach use Logger with Firebase Crashlytics. Maybe this example give an idea for you. Extend Default Logger (mm_logger.dart) I only override error method because I just want to log errors in Firebase Crashlytics you can override another methods if you want.

class MMLogger extends Logger {
  /// Create a new instance of MMLogger.
  ///
  /// You can provide a custom [printer], [filter] and [output]. Otherwise the
  /// defaults: [PrettyPrinter], [DevelopmentFilter] and [ConsoleOutput] will be
  /// used.
  MMLogger({
    LogFilter? filter,
    LogPrinter? printer,
    LogOutput? output,
    Level? level,
  }) : super(filter: filter, printer: printer, output: output, level: level);

  @override
  void e(dynamic message, [dynamic error, StackTrace? stackTrace]) {
    super.e(message, error, stackTrace);
    FirebaseCrashlytics.instance.recordError(error, stackTrace,
        // reason: 'a fatal error',
        // Pass in 'fatal' argument
        fatal: true);
  }
}

Create instance from MMLogger instead of Default Logger (main.dart):

final logger = MMLogger(
  filter: null, // Use the default LogFilter (-> only log in debug mode)
  printer: PrettyPrinter(), // Use the PrettyPrinter to format and print log
  output: null, // Use the default LogOutput (-> send everything to console)
);