TestLogger class

A convenience wrapper that creates an isolated logger with a CaptureSink for unit testing.

On construction, TestLogger calls Logger.configure to register the logger globally by name. This means the name is visible to the entire Logger registry for the lifetime of the test.

Always call dispose in a tearDown or addTearDown callback to remove the logger registration and avoid name collisions across tests:

late TestLogger testLogger;

setUp(() => testLogger = TestLogger('my_logger'));
tearDown(() => testLogger.dispose());

Constructors

TestLogger(String name)
Creates a TestLogger and configures it with a CaptureSink.

Properties

hashCode int
The hash code for this object.
no setterinherited
logger Logger
Gets the Logger instance.
no setter
logs List<CapturedLog>
Gets the list of captured logs.
no setter
name String
The name of the logger under test.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sink CaptureSink
The sink capturing logs.
final

Methods

clear() → void
Clears all captured logs.
dispose() → void
Removes this logger's configuration from the global Logger registry.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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