configureLogger static method

void configureLogger(
  1. String? filePath, {
  2. Level printLevel = Level.ALL,
  3. Level rootLevel = Level.ALL,
  4. bool continueOnError = false,
  5. @Deprecated('Use other levels and flags to control verbosity') bool enableDebugMesage = false,
})

Sets up logging to dump to filePath (if provided) and print to console based on printLevel and rootLevel.

The rootLevel will set the level of the Logger.root to the given level.

The printLevel is the Level from Loggers that should be printed to the console. This can at most print Levels that are enabled in the Logger.root.

If continueOnError is set to false, then an exception will be thrown immediately upon encountering an error.

Implementation

static void configureLogger(
  String? filePath, {
  Level printLevel = Level.ALL,
  Level rootLevel = Level.ALL,
  bool continueOnError = false,
  @Deprecated('Use other levels and flags to control verbosity')
  bool enableDebugMesage = false,
}) {
  RohdBridgeLogger.continueOnError = continueOnError;
  Logger.root.level = rootLevel;
  _printLevel = printLevel;

  if (filePath != null) {
    final file = File(filePath);
    final directory = file.parent;
    if (!directory.existsSync()) {
      directory.createSync(recursive: true);
    }

    _fileSink = file.openWrite();
  }

  Logger.root.onRecord.listen((record) {
    final message = '${record.time}: ${record.level.name}: '
        '${record.message}\n';

    _handleMessage(message, record.level);
  });
}