Log class

A logger that delegates to a LogWriter and resolves the current LogScope from the Zone.

Each call appends onto a rolling _latest Future, so writes serialize in invocation order. flush awaits that tail; close does the same and blocks further dispatches.

log.info('Server started');
await log.progress('Migration', () async {
  log.info('Step 1');
});
Available extensions

Constructors

Log(LogWriter _writer, {LogLevel logLevel = LogLevel.info})
Creates a Log that forwards to _writer. Messages below logLevel are dropped before the LogEntryFactory runs.

Properties

currentScope LogScope
The current scope from the Zone, or a synthetic root if none.
no setter
hashCode int
The hash code for this object.
no setterinherited
isDebugEnabled bool

Available on Log, provided by the LogConvenience extension

Whether debug-level messages are currently forwarded to the writer. Use to gate expensive message construction: if (log.isDebugEnabled) log.debug(formatBigObject(x));.
no setter
logLevel LogLevel
The minimum severity that will be forwarded to the writer. Calls below this level short-circuit without invoking the LogEntryFactory. May be changed at runtime (e.g. when a verbose flag is parsed).
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(LogLevel level, LogEntryFactory factory) → void
Checks level, evaluates the factory eagerly, and appends the write to the chain. Writer errors are swallowed - logging is best-effort.
close() Future<void>
Awaits in-flight writes and blocks further dispatches.
debug(String message, {Map<String, Object?>? metadata}) → void

Available on Log, provided by the LogConvenience extension

Logs message at LogLevel.debug.
error(String message, {Object? error, StackTrace? stackTrace, Map<String, Object?>? metadata}) → void

Available on Log, provided by the LogConvenience extension

Logs message at LogLevel.error, optionally attaching an error value and stackTrace.
flush() Future<void>
Awaits in-flight writes without blocking further dispatches.
info(String message, {Map<String, Object?>? metadata}) → void

Available on Log, provided by the LogConvenience extension

Logs message at LogLevel.info.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
progress<T>(String label, FutureOr<T> runner(), {Map<String, Object?>? metadata, bool isSuccess(T result)?}) Future<T>

Available on Log, provided by the LogScoping extension

Runs runner inside a new scope. The scope is automatically opened before the runner and closed after it completes (or fails).
toString() String
A string representation of this object.
inherited
warning(String message, {Map<String, Object?>? metadata}) → void

Available on Log, provided by the LogConvenience extension

Logs message at LogLevel.warning.

Operators

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