init method

  1. @override
Future<void>? init(
  1. Map<String, dynamic> config,
  2. bool test,
  3. DateTime? date
)
override

Setup the appender. This needs to be called for every appender to configure the appender with the necessary data.

Implementation

@override
Future<void>? init(
    Map<String, dynamic> config, bool test, DateTime? date) async {
  created = date ?? DateTime.now();
  type = AppenderType.FILE;
  if (config.containsKey('format')) {
    format = config['format'];
  } else {
    format = Appender.defaultFormat;
  }
  if (config.containsKey('dateFormat')) {
    dateFormat = config['dateFormat'];
  } else {
    dateFormat = Appender.defaultDateFormat;
  }
  if (config.containsKey('filePattern')) {
    filePattern = config['filePattern'];
  } else {
    throw ArgumentError('Missing file argument for file appender');
  }
  if (config.containsKey('fileExtension')) {
    fileExtension = config['fileExtension'];
  }
  if (config.containsKey('rotationCycle')) {
    rotationCycle = Utils.getRotationCycleFromString(config['rotationCycle']);
  }
  if (config.containsKey('level')) {
    level = Level.fromString(config['level']);
  } else {
    level = Level.INFO;
  }
  if (config.containsKey('path')) {
    path = config['path'];
  }
  if (!test) {
    if (FileSystemEntity.typeSync(_getFullFilename()) ==
        FileSystemEntityType.notFound) {
      _file = await File(_getFullFilename()).create();
    } else {
      _file = File(_getFullFilename());
    }
  }
  return null;
}