Logger is used to emit logging messages.
There are three types of Logger:
- Hierarchical logger: Named logger using dot-separated namespaces.
- Detached logger: Optionally named logger not part of any logger hierarchy.
- Noop logger: Logger that does nothing.
Obtain Logger objects using:
- Logger.getLogger: Returns a hierarchical logger (creates or retrieves existing).
- Logger.detached: Always returns a new logger, useful for short-lived loggers.
- Logger.noop: Returns a no-operation logger.
Each logger has:
- A severity level (Logger.level) defining the minimum severity it handles.
- An optional filter (Logger.filter) to further refine which messages are logged.
Use Logger.log or its derivatives (Logger.debug
, Logger.info
, etc.) to log messages.
The logger checks:
- Severity level
- Filter (if any)
- Delegates to the registered handler (if any, see Logger.handler)
Use Logger.withFields to bind structured data to the logging context.
- Implemented types
- Implementers
- Available extensions
Constructors
- Logger.detached([String? name])
-
Creates a new detached logger.
factory
- Logger.getLogger(String name)
-
Retrieves or creates a logger with the given
name
.factory - Logger.noop()
-
Creates a new noop logger which never emits logs or delegates records to handlers.
factory
Properties
- filter ← Filter?
-
Sets this logger's filter.
no getter
- handler ← Handler?
-
Sets this logger's handler.
no getter
- hashCode → int
-
The hash code for this object.
no setterinherited
- level ↔ Level
-
Gets the minimum severity level of Records this logger handles.
getter/setter pair
- name → String?
-
Name of this logger.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
debug(
String message, [Iterable< Field> ? fields]) → void -
Available on Interface, provided by the DefaultLog extension
Emits a record withmessage
and Level.debug severity level. -
error(
String message, [Iterable< Field> ? fields]) → void -
Available on Interface, provided by the DefaultLog extension
Emits a record withmessage
and Level.error severity level. -
fatal(
String message, [Iterable< Field> ? fields]) → void -
Available on Interface, provided by the DefaultLog extension
Emits a record withmessage
and Level.fatal severity level. -
info(
String message, [Iterable< Field> ? fields]) → void -
Available on Interface, provided by the DefaultLog extension
Emits a record withmessage
and Level.info severity level. -
isEnabledFor(
Level level) → bool -
Checks if a record with the given severity
level
will be emitted by this logger. -
log(
Level level, String message, [Iterable< Field> ? fields]) → void -
Emits a record with
message
andlevel
severity level.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
startTimer(
String message, {Level level = Level.info}) → Timer -
Starts tracing and emits a record with
message
andlevel
severity level; to stop tracing call Timer.stop on the returned timer.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
warn(
String message, [Iterable< Field> ? fields]) → void -
Available on Interface, provided by the DefaultLog extension
Emits a record withmessage
and Level.warn severity level. -
withFields(
Iterable< Field> fields) → Interface -
Creates and returns a new logging context with bound collection of
fields
added to existing ones.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited