IsolateLogSink class final
Sink that passes entries to another isolate through port (IsolateLogReceiver.sendPort) without persisting them. There they go through the root logger alongside its own entries: same threshold, processors, sinks and store.
For an isolate the sender owns and whose port it received at spawn: a
worker the main isolate started logs into the main root, whose sinks and
store stay where the viewer reads them; it is not a way to move a store out
of the main isolate. SendPort.send does not confirm delivery: if the
receiver is closed (IsolateLogReceiver.close) or its isolate has exited,
entries are lost silently, so engine-started isolates (FCM, WorkManager)
use LogSpoolSink, which writes to disk and uses the port only as a
notification.
An entry is sent in logEntryJson form: a map of strings, numbers, lists and maps, which SendPort.send delivers even to an isolate of another group without shared code. It is not encoded as JSON text: the receiver should not have to parse it. As with persistence, only the live LogError.original and LogError.report are lost.
Sends in add, during root dispatch. An isolate that exits right after its
work (Isolate.run) would lose entries waiting for dispatch until the next
event-loop turn, so its root is given dispatch in the logger call
(LogDispatchPolicy.synchronous):
Future<void> work(SendPort logPort) async {
final logger = RootLogger(sinks: [IsolateLogSink(logPort)], dispatch: LogDispatchPolicy.synchronous)
..finishStartup();
logger.child(tags: {'sync'}).log('Sync started');
}
await Isolate.run(() => work(receiver.sendPort));
Constructors
- IsolateLogSink(SendPort port)
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
- 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
--obfuscatebuild that is unreadable (minified:aB); the library's sinks return a constant string, and a custom sink should do the same.no setteroverride - port → SendPort
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
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
RootLoggerfan-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.addSinkand 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):
RootLoggercalls 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, beforelogreturns. 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
diagnosticsto inner sinks. Does nothing by default;DelegatingSinkpasses it toinner.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 toinner.inherited -
onClose(
) → Future< void> -
Delivers accepted entries and releases resources (for example closes the
store). Called once. Does nothing by default.
inherited
-
onFlush(
) → Future< void> -
Waits for accepted entries to be delivered. Does nothing by default: for
sinks that deliver entries immediately in onAdd.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited