configureLogger static method

void configureLogger(
  1. String filePath, {
  2. Level printLevel = Level.ALL,
  3. Level rootLevel = Level.ALL,
  4. bool continueOnError = false,
  5. bool enableDebugMesage = false,
})

Sets up logging to dump to filePath 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,
  bool enableDebugMesage = false,
}) {
  RohdBridgeLogger.continueOnError = continueOnError;
  Logger.root.level = rootLevel;
  _printLevel = printLevel;

  fileSink = File(filePath).openWrite();

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

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