AsyncFileOutput class
Non-blocking file output: appends JSON lines to a file without blocking the calling isolate. Writes are serialized and delivered in order; a failing write is caught and reported to stderr without affecting later writes. Directories are created eagerly (synchronously) at construction.
Prefer this over fileOutput for high-throughput logging, where
blocking on disk I/O for every call would be wasteful. Keep a reference
to the instance (rather than only passing it as output:) so you can
await flushed — e.g. in tests, or right before your process exits,
to make sure every queued write has actually landed on disk.
final asyncOutput = AsyncFileOutput('logs/async.log');
StructlogConfiguration.configure(output: asyncOutput);
final log = getLogger();
log.info('async_event_1');
log.info('async_event_2');
// Without this, the process could exit before the writes land.
await asyncOutput.flushed;
Constructors
- AsyncFileOutput(String filePath)
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
- 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