Skip to content

Logger replacement for Fimber #136

@adrianvintu

Description

@adrianvintu

Since the plugin is not working and the dev does not have time to fix it #135 (comment), i quickly hacked a replacement solution. Maybe it helps someone.

pubspec.yaml

...
logging: ^1.2.0
...

main.dart

//removing fimber because it is a broken plugin
Future<void> _setupFimberLog() async {
  // Fimber.clearAll();
  // Fimber.plantTree(FimberTree());

  var directory = await getApplicationDocumentsDirectory();
  final fileName = "fimber_log.txt";
  final filePath = "${directory.path}/$fileName";

  //delete file if > than 1M
  var file = File(filePath);
  if (file.existsSync() && file.lengthSync() > 1 * 1024 * 1024) {
    print("deleting log file $filePath with length ${file.lengthSync()}");
    file.deleteSync();
  }

  // Fimber.plantTree(FimberFileTree(filePath,
  //     logFormat:
  //         "${CustomFormatTree.timeStampToken}\t${CustomFormatTree.messageToken}\t${CustomFormatTree.timeElapsedToken}"));

  Logger.root.level = Level.ALL; // defaults to Level.INFO
  Logger.root.onRecord.listen((record) {
    String message = '${record.message}';
    if (record.level.value >= Level.WARNING.value)
      message = '${record.level.name}: ${record.time}:  ${record.message}';
    print(message);
    String content = '${record.level.name}: ${record.time}: ${record.message}';
    file.writeAsString(content, mode: FileMode.append, flush: true);
  });
}

debug.dart

class Debug {
  static d(String string) {
    //Fimber.d(string);
    Logger("debug").fine(string);
  }

  static e(String string) {
    //Fimber.e(string);
    Logger("debug").severe(string);
  }

  static ex(String string, dynamic e, StackTrace s) {
    Logger("debug").severe(string, e, s);
  }
}

Thank you for the developer for giving us the Fimber plugin, hope it will be updated sometime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions