Logger class
Advanced logger implementation that provides structured logging capabilities. This logger supports multiple channels, configurable handlers, and proper separation of concerns.
Features:
- Multiple log channels for different parts of the application
- Configurable log levels and filtering
- Support for structured logging with context
- Pluggable log handlers (console, file, etc.)
- Automatic configuration loading from application config
Example usage:
final logger = Logger();
logger.info('Application started', context: {'version': '1.0.0'});
logger.error('Database connection failed', context: {'error': e.toString()});
- Implemented types
Constructors
- Logger({LogLevel minimumLevel = LogLevel.debug, LogChannelManager? channelManager})
- Creates a new logger instance.
Properties
- defaultChannel → String
-
Gets the default channel
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- minimumLevel ↔ LogLevel
-
Gets the minimum log level
getter/setter pairoverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addHandler(
LogHandler handler, {String channel = 'app'}) → void -
Adds a log handler to a specific channel.
override
-
close(
) → void -
Closes all log handlers and releases resources.
This should be called when the logger is no longer needed.
override
-
critical(
String message, {Map< String, dynamic> ? context, StackTrace? stackTrace, String? channel}) → void -
Logs a critical message.
override
-
debug(
String message, {Map< String, dynamic> ? context, StackTrace? stackTrace, String? channel}) → void -
Logs a debug message.
override
-
error(
String message, {Map< String, dynamic> ? context, StackTrace? stackTrace, String? channel}) → void -
Logs an error message.
override
-
info(
String message, {Map< String, dynamic> ? context, StackTrace? stackTrace, String? channel}) → void -
Logs an info message.
override
-
loadFromConfig(
ConfigInterface config, {String channel = "app"}) → void -
Loads logger configuration from the application config system.
override
-
log(
LogLevel level, String message, {Map< String, dynamic> ? context, StackTrace? stackTrace, String? channel}) → void -
Logs a message with a specific level.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setDefaultChannel(
String channel) → void -
Sets the default channel for logging operations.
override
-
toString(
) → String -
A string representation of this object.
inherited
-
warning(
String message, {Map< String, dynamic> ? context, StackTrace? stackTrace, String? channel}) → void -
Logs a warning message.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited