RollingFileSink class
Appends events to a file, rotating when the current file exceeds a
size threshold. Keeps up to keep older files on disk (foo.log.1,
foo.log.2, …) and deletes the oldest on rotation.
Rotation is size-based and triggered lazily on write — this avoids needing a background timer. Callers may also rotate on demand via rotate. As with FileSink, all errors are swallowed.
- Implemented types
Constructors
- RollingFileSink({required String path, LogFormatter? formatter, int maxBytes = 5 * 1024 * 1024, int keep = 5})
- Creates a rolling file sink.
Properties
- formatter → LogFormatter
-
Formatter for lines. Defaults to JSON.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- keep → int
-
Maximum number of rotated files retained. The oldest is deleted
during rotation when this limit is reached.
final
- maxBytes → int
-
Rotate when the live file reaches this size, in bytes.
final
- name → String
-
Short diagnostic name for this sink (used by
LoggerHealth).no setteroverride - path → String
-
Path of the "live" file — e.g.
/var/log/app.log. Rotated files are named<path>.1,<path>.2, …final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> -
Releases any resources held by this sink. After close returns, the
sink must not accept any more events.
override
-
flush(
{Duration timeout = const Duration(seconds: 2)}) → Future< void> -
Flushes any pending buffered events to the underlying transport.
Returns a future that completes when all buffered events have been
written, or when
timeoutelapses, whichever is first.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
rotate(
) → Future< void> - Rotates the current file immediately, closing the live sink, shifting older files, and reopening a fresh live file.
-
toString(
) → String -
A string representation of this object.
inherited
-
write(
LogEvent event) → void -
Consumes
event. Must not throw. May be asynchronous internally.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited