Logger class

A flexible and extensible logging interface.

The Logger class provides structured and leveled logging functionality across your application. It wraps a LoggingListener that handles how logs are processed and output—making it customizable through the strategy pattern.

This class offers six common logging levels:

  • info – General operational messages.
  • debug – Development and debugging messages.
  • trace – Fine-grained, low-level application traces.
  • warning – Warning messages about unexpected conditions.
  • error – Errors that occurred during execution.
  • fatal – Critical errors that may require immediate attention.

Example:

console.info('Server started');
console.error('Unexpected error occurred', error: e, stackTrace: s);

Constructors

Logger({LogLevel level = LogLevel.INFO, LogPrinter? printer, LogType type = LogType.SIMPLE, void output(String)?, String name = "", LogConfig? config, LoggingListener? listener})
A flexible and extensible logging interface.

Properties

hashCode int
The hash code for this object.
no setterinherited
listener LoggingListener
The current log listener responsible for handling the log output logic.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(LoggingListener listener) → void
Replaces the current LoggingListener with a custom implementation.
debug(dynamic message, {String? tag, Object? error, StackTrace? stackTrace}) → void
Logs a message with LogLevel.DEBUG.
error(dynamic message, {String? tag, Object? error, StackTrace? stackTrace}) → void
Logs a message with LogLevel.ERROR.
fatal(dynamic message, {String? tag, Object? error, StackTrace? stackTrace}) → void
Logs a message with LogLevel.FATAL.
info(dynamic message, {String? tag, Object? error, StackTrace? stackTrace}) → void
Logs a message with LogLevel.INFO.
log(dynamic message, {String? tag, Object? error, StackTrace? stackTrace, LogLevel level = LogLevel.INFO}) → void
Logs a message with a specified log level.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
trace(dynamic message, {String? tag, Object? error, StackTrace? stackTrace}) → void
Logs a message with LogLevel.TRACE.
warn(dynamic message, {String? tag, Object? error, StackTrace? stackTrace}) → void
Logs a message with LogLevel.WARN.

Operators

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