LogStoreSink class final

A sink that persists entries to store.

Entries are written in batches in arrival order, one LogStore.writeEntries at a time: a write starts at the end of the root's dispatch (endBatch) if the store is idle, otherwise right after the current write. A fatal entry the root dispatches inside the logger call therefore reaches a synchronous store before log returns, if the store is not busy. A batch holds at most maxBatchSize entries, so a synchronous store never blocks the isolate for a thousand-entry transaction; the rest follows in later batches with the event loop yielded between them.

The queue is bounded by queueLimit: if the store cannot keep up, the oldest waiting entries are dropped and the next batch carries a warning with their count (storageLogTag). flush waits for the entries accepted before the call; close waits for everything accepted. The sink does not own the store, which the application reads concurrently and closes itself after the logger:

logger.addSink(RepeatCollapsingSink(LogStoreSink(store)));
// …
await logger.close(); // waits until everything accepted is written
await store.close();
Inheritance

Constructors

LogStoreSink(LogStore store, {int queueLimit = 1000, int maxBatchSize = 100, LogWriteErrorHandler? onWriteError})

Properties

diagnostics → DiagnosticReporter
Where the sink reports its own failures. Set by the logger on attach (attach); before that, DiagnosticReporter.console.
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
isClosed → bool
Whether close has been called: from then on add throws.
no setterinherited
maxBatchSize → int
Maximum number of entries in one LogStore.writeEntries call (the overflow warning does not count). For a synchronous store this bounds how long one transaction blocks the isolate; smaller means shorter blocking but more transactions.
final
name → String
Sink name in library messages: in diagnostics (LogDiagnostic) and in the dropped-entries warnings that go into the log. Defaults to the class name, but in an --obfuscate build that is unreadable (minified:aB); the library's sinks return a constant string, and a custom sink should do the same.
no setteroverride
onWriteError → LogWriteErrorHandler?
Called when the store failed to persist a batch; without it the failure goes to diagnostics, like queue overflow and a failure of the handler itself. Entries from the batch are not retried.
final
queueLimit → int
Maximum number of entries waiting for the store. On overflow the oldest are dropped: with a looping error the latest events matter more. The limit is mandatory: a hung or slow store would otherwise eat memory while the app keeps logging.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
store → LogStore
final

Methods

add(LogEntry entry) → void
Accepts an entry (onAdd). Throws StateError after close: logging into a closed sink is a shutdown-order bug, better seen than silently sent to a closed store. The RootLogger fan-out catches such errors and reports them to diagnostics.
inherited
attach(DiagnosticReporter diagnostics) → void
Tells the sink where to send reports of its own failures (diagnostics). Called by the logger on attach (RootLogger.addSink and the sinks from the root constructor); wrappers pass the channel to their inner sinks (onAttach). A repeated call replaces the channel: a sink reattached to another logger reports to it.
inherited
close() → Future<void>
Shuts the sink down: no new entries are accepted, then onClose delivers the accepted ones and releases resources. A repeated call closes nothing again and returns the result of the first.
inherited
endBatch() → void
Signals that a batch of entries has ended (onBatchEnd): RootLogger calls it after every queue dispatch, including dispatch inside the logger call (a fatal entry, flush, close). A sink that writes in batches (LogStoreSink) hands over what it accumulated here: everything the root dispatched at once goes as one batch, and a fatal entry goes together with what accumulated before it, before log returns. Does nothing after close.
inherited
flush() → Future<void>
Waits until accepted entries reach their destination (for example are persisted to the store) without closing the sink (onFlush). After close, waits for the closing to complete, which delivers everything accepted.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onAdd(LogEntry entry) → void
Handles an accepted entry. Called only before close.
override
onAttach(DiagnosticReporter diagnostics) → void
Called from attach: pass diagnostics to inner sinks. Does nothing by default; DelegatingSink passes it to inner.
inherited
onBatchEnd() → void
Called from endBatch. Does nothing by default: for sinks that handle each entry in onAdd; wrappers (DelegatingSink) pass the end of batch to inner.
override
onClose() → Future<void>
After close there are no new entries, so waits for the whole queue to be written. Does not close store: the app owns it.
override
onFlush() → Future<void>
Starts writing what accumulated, if not already in progress, and waits until entries accepted before this call are handed to the store (persisted or passed to onWriteError) or dropped on overflow, however many batches that takes. Does not wait for entries accepted later: otherwise, with continuous logging faster than the store writes, it would never complete.
override
toString() → String
A string representation of this object.
inherited

Operators

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