FileLogger constructor

FileLogger({
  1. required String logFilePath,
  2. int maxFileSizeInBytes = 10 * 1024 * 1024,
  3. int maxBackupFiles = 5,
  4. Encoding encoding = utf8,
  5. int batchSize = 1,
  6. Duration flushInterval = const Duration(seconds: 2),
  7. LoggerFormatter? formatter,
  8. LoggerDateFormatter? dateFormatter,
})

Creates a new instance of FileLogger.

logFilePath is the path to the log file. maxFileSizeInBytes is the maximum size of the log file in bytes before rotation. Defaults to 10MB. maxBackupFiles is the maximum number of backup files to keep. Defaults to 5. encoding is the encoding to use for writing to the file. Defaults to utf8. batchSize is the number of log messages to buffer before writing to the file. Defaults to 1 (no buffering). flushInterval is the interval at which to flush the buffer to the file. Defaults to 2 seconds. formatter is the default formatter for log messages. If not provided, a default formatter is used.

Implementation

FileLogger({
  required this.logFilePath,
  this.maxFileSizeInBytes = 10 * 1024 * 1024,
  this.maxBackupFiles = 5,
  this.encoding = utf8,
  this.batchSize = 1,
  this.flushInterval = const Duration(seconds: 2),
  super.formatter,
  super.dateFormatter,
}) : super(
       id: '${DateTime.now().microsecondsSinceEpoch}_${logFilePath.hashCode}',
     ) {
  LogDispatcher.createWorker(id, {
    'worker': (FileLoggerWorker).toString(),
    'logFilePath': logFilePath,
    'maxFileSizeInBytes': maxFileSizeInBytes,
    'maxBackupFiles': maxBackupFiles,
    'encoding': encoding.name,
    'batchSize': batchSize,
    'flushIntervalMs': flushInterval.inMilliseconds,
  });
}