logger
logger copied to clipboard
[Questions] - How to send error level logs in crashlytics ?
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
I too am interested see documentation added for how I can send my logs to sentry.io
It looks like we can use the LogOutput class to send events to a network target.
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.
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)
);