LoggingListener class abstract
A listener interface for reacting to logging events within an application.
The TracingListener
interface allows you to observe and respond to log messages
generated by instances of TracingListener
. This is useful for implementing
custom log processing, such as writing logs to:
- The console (standard output)
- External log files
- Remote logging services (e.g., Datadog, Sentry)
- In-memory dashboards or UIs
How to Implement
To respond to logs, implement this interface and override onLog:
class ConsoleLogListener implements TracingListener {
@override
void onLog(LogLevel level, DateTime timestamp, String message, String tag) {
print('[$timestamp][$tag][$level] $message');
}
}
Integration with Logger Factory
Register the listener with a logger:
final logger = MyLoggerFactory("DatabaseService");
logger.registerListener(ConsoleLogListener());
logger.add(LogLevel.info, "Database connection established.");
This enables a plug-and-play model where multiple listeners can be registered and independently respond to log events.
- Implementers
Constructors
- LoggingListener({LogLevel level = LogLevel.INFO, LogPrinter? printer, LogType type = LogType.SIMPLE, void output(String)?, String name = "", LogConfig? config})
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.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited