FileLogHandler constructor

FileLogHandler({
  1. required String logNamePrefix,
  2. required int maxLogSizeInMb,
  3. required int maxFilesCount,
  4. required Directory logFileDirectory,
  5. List<BDLevel> supportedLevels = const <BDLevel>[BDLevel.warning, BDLevel.success, BDLevel.error],
  6. BDLogFormatter logFormatter = const DefaultLogFormatter(),
})

Create a new instance of FileLogHandler.

logNamePrefix will be used as prefix for each log file created by the instance of this FileLogHandler. It's recommended that the logNamePrefix be unique in the app.

maxLogSizeInMb in MB will be used as the maximum size of each log file created by the instance of this FileLogHandler.

maxFilesCount will be used to deleted old log files. If in the logFileDirectory there's files with prefix logNamePrefix and the count of files is greater than maxFilesCount, older files will be deleted.

logFileDirectory is the directory where log files will be stored.

We assume that the logFileDirectory provide exist in the file system.

supportedLevels will be used to discard BDLogRecord with BDLevel lower than supportedLevels.

Implementation

FileLogHandler({
  required this.logNamePrefix,
  required this.maxLogSizeInMb,
  required this.maxFilesCount,
  required this.logFileDirectory,
  this.supportedLevels = const <BDLevel>[
    BDLevel.warning,
    BDLevel.success,
    BDLevel.error,
  ],
  this.logFormatter = const DefaultLogFormatter(),
})  : assert(
        logNamePrefix.isNotEmpty,
        'logNamePrefix should not be empty',
      ),
      assert(
        maxLogSizeInMb > 0,
        'maxLogSizeInMb should not be lower than zero',
      );