initializeLogger function

void initializeLogger({
  1. Level level = kDebugMode ? Level.ALL : Level.SEVERE,
})

it will initialize the logger for the app

Implementation

void initializeLogger({Level level = kDebugMode ? Level.ALL : Level.SEVERE}) {
  Logger.root.level = Level.ALL; // defaults to Level.INFO
  Logger.root.onRecord.listen((LogRecord record) {
    final text = '${record.time}: ${record.message}';
    if (<Level>[Level.WARNING, Level.SEVERE, Level.SHOUT]
        .contains(record.level)) {
      _debugPrintColoredLine(text, 'red');
    } else if (<Level>[
      Level.FINE,
    ].contains(record.level)) {
      _debugPrintColoredLine(text, 'green');
    } else {
      _debugPrintColoredLine(text, 'yellow');
    }
  });
}