DefaultLoggingListener class final
A default implementation of LoggingListener that outputs logs to the console.
DefaultLoggingListener provides a simple and human-readable logging mechanism
by printing log messages to the standard output (stdout
). Each log entry is timestamped,
tagged, and categorized by LogLevel.
This listener is ideal for:
- Development and debugging environments
- Local testing
- Simple CLI applications
Output Format
Logs are printed in the following format:
[2025-06-18 14:22:01.534][MyService][info] Service started successfully.
[2025-06-18 14:22:05.882][Database][error] Connection failed: Timeout
Example Usage
final logger = MyCustomLogger('Database');
final listener = DefaultApplicationLogListener();
logger.add(LogLevel.error, 'Connection failed');
// Somewhere internally, the listener gets notified:
listener.onLog(LogLevel.error, DateTime.now(), 'Connection failed', 'Database');
Integration with Logging System
To use this with a custom logger or broadcasting mechanism:
final listener = DefaultApplicationLogListener();
void broadcastLog(LogLevel level, String message, String tag) {
final now = DateTime.now();
listener.onLog(level, now, message, tag);
// other listeners can also be notified here
}
- Inheritance
-
- Object
- LoggingListener
- DefaultLoggingListener
Constructors
- DefaultLoggingListener({LogLevel level = LogLevel.INFO, LogPrinter? printer, LogType type = LogType.SIMPLE, void output(String)?, String name = "", LogConfig? config})
- A default implementation of LoggingListener that outputs logs to the console.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onLog(
LogLevel level, dynamic message, {String? tag, Object? error, StackTrace? stackTrace}) → void -
Called when a new log entry is emitted by a logger.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited