io library
The file outputs of structured_log, which need dart:io.
Kept apart from package:structured_log/structured_log.dart so that the
main library compiles — and is marked as supported — on every platform,
the web included. Import this alongside it where entries go to a file:
import 'package:structured_log/io.dart';
import 'package:structured_log/structured_log.dart';
StructlogConfiguration.configure(output: fileOutput('logs/app.log'));
Classes
- AsyncFileOutput
- 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.
- AsyncRotatingFileOutput
-
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.
Functions
-
fileOutput(
String filePath) → OutputFunction -
Returns an OutputFunction that appends each entry as a single-line
JSON object to the file at
filePath, synchronously. The file (and any missing parent directories) is created on first write if it doesn't exist; existing content is preserved and new lines are appended. -
rotatingFileOutput(
String filePath, {int maxSizeBytes = 10 * 1024 * 1024, int maxBackups = 5}) → OutputFunction -
Returns an OutputFunction like fileOutput, but rotates the file once
it reaches
maxSizeBytes: before a write that would exceed the limit, the current file is renamed to<filePath>.0, any existing.0becomes.1, and so on up to.{maxBackups - 1}— the oldest backup beyond that is deleted. A fresh file atfilePathis then created for the new entry. Writing (and rotation) is synchronous; for a non-blocking version see AsyncRotatingFileOutput.