Log class

Zone-based logger with automatic context propagation.

Use Log.named to create a named logger for classes:

class UserService {
  static final log = Log.named('UserService');

  Future<User> findUser(String id) async {
    log.info('Finding user', {'userId': id});
    // Output: ... [INFO] Finding user logger=UserService userId=42
    return await _repository.find(id);
  }
}

For quick logging without a class name, use the top-level log constant:

log.info('message');

Properties

hashCode int
The hash code for this object.
no setterinherited
name String?
Logger name (typically the class name).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

debug(String message, [Map<String, dynamic>? fields]) → void
Logs a debug message.
error(String message, [Map<String, dynamic>? fields, Object? err, StackTrace? stackTrace]) → void
Logs an error message.
info(String message, [Map<String, dynamic>? fields]) → void
Logs an info message.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
warn(String message, [Map<String, dynamic>? fields]) → void
Logs a warning message.

Operators

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

Static Properties

currentContext Map<String, dynamic>
Gets the current zone context fields.
no setter

Static Methods

named(String name) Log
Creates a named logger.
scope<R>(Map<String, dynamic> fields, R fn()) → R
Runs the given function within a log context zone.