AsyncRotatingFileOutput class

Non-blocking file output with rotation: like AsyncFileOutput, but rotates to .0, .1, ... .{maxBackups - 1} once the file exceeds maxSizeBytes. The size check, rotation, and write are all serialized through the same write queue, so they never race with themselves.

The non-blocking counterpart of rotatingFileOutput; see AsyncFileOutput for why and how to use flushed. Like it, the size is read once, at construction, and counted in memory from then on.

final asyncRotating = AsyncRotatingFileOutput(
  'logs/app.log',
  maxSizeBytes: 1024 * 1024, // 1 MB per file
  maxBackups: 5,
);
StructlogConfiguration.configure(output: asyncRotating);

final log = getLogger();
for (var i = 0; i < 100000; i++) {
  log.info('iteration', context: {'i': i});
}
await asyncRotating.flushed;

Constructors

AsyncRotatingFileOutput(String filePath, {int maxSizeBytes = 10 * 1024 * 1024, int maxBackups = 5})

Properties

filePath → String
final
flushed → Future<void>
Completes once every write enqueued so far has finished — either successfully or after being caught and reported. Await this in tests, or before process exit, to know all writes have landed.
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
maxBackups → int
final
maxSizeBytes → int
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(Map<String, dynamic> entry, LogLevel level) → void
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited