CallbackSink class

A LogSink that forwards records to a plain callback.

Warning: The callback runs synchronously during the logging call, which may be inside Flutter's build/layout phase. If your callback calls setState, notifyListeners, or any method that triggers a rebuild, Flutter will throw setState() called during build.

For UI-affecting callbacks, use BufferedCallbackSink (timer-deferred) or AsyncLogSink (microtask-deferred) instead:

// WRONG — causes build-during-build crash:
CallbackSink((r) => setState(() => logs.add(r)))

// RIGHT — timer-deferred, safe for UI:
BufferedCallbackSink(onFlush: (batch) => setState(() => logs.addAll(batch)))

CallbackSink is safe for fire-and-forget work that does not touch widget state: crash reporters, analytics events, file writes.

LogPilotConfig(
  sinks: [
    CallbackSink((record) {
      FirebaseCrashlytics.instance.log(record.message ?? '');
    }),
  ],
)
Implemented types

Constructors

CallbackSink(void _callback(LogPilotRecord record))
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

dispose() → void
Release any resources held by this sink.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onLog(LogPilotRecord record) → void
Called for every log record that passes the level and tag filters.
override
toString() String
A string representation of this object.
inherited

Operators

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