logger icon indicating copy to clipboard operation
logger copied to clipboard

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

Open kristijorgji opened this issue 2 years ago • 4 comments

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

kristijorgji avatar May 13 '22 11:05 kristijorgji

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

Desync-o-tron avatar May 13 '22 20:05 Desync-o-tron

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

Desync-o-tron avatar May 13 '22 20:05 Desync-o-tron

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

haroonkhan9426 avatar Jun 19 '22 09:06 haroonkhan9426

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)
);

ayberkcal avatar Nov 15 '22 11:11 ayberkcal