Skip to content

Write errors higher than a specific level to crashlytics #21

@sarthakydv

Description

@sarthakydv

In our apps, we are catching lots of exceptions but in some cases, it would be good to have them reported back to us.
I am currently integrating crashlytics into it.

I made a CrashlyticsLogPrinter that along with a few extra changes can work but I would still be returning an empty list.
Please suggest alternatives to this approch.
I am thinking that a custom LogOutput might help but it works on a line by line basis, I am not sure how I can use it to write a proper log on crashlytics.

Any advice will be deeply appreciated

import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:logger/logger.dart';

class CrashlyticsLogPrinter extends LogPrinter {
  final String _className;
  final FirebaseCrashlytics? _firebaseCrashlytics;

  KodomamoCrashlyticsLogPrinter(this._className, this._firebaseCrashlytics);

  @override
  List<String> log(LogEvent event) {
    /// This sends logs of warning level and above to Crashlytics
    if (event.level.index >= Level.warning.index) {
      _firebaseCrashlytics!.recordError(
        event.message,
        event.stackTrace,
        fatal: true,
        information: [_className, event.level],
        printDetails: false,
      );
    }
    return [];
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions