RecordingHandler class

A Handler that keeps records in memory for tests.

Install it as the only handler in your test setup. That silences other output and gives you a list of records to look at:

final recorder = RecordingHandler();
LogConfig.configure(handlers: [recorder]);

// ... run the code under test ...

expect(recorder.records, hasLength(1));
expect(recorder.atOrAbove(Level.error), isEmpty);
expect(recorder.from('app.publish').first.fields['orderId'], 'abc');

All filter getters return lazy Iterables, so chained calls stay cheap. Call clear between test cases if you reuse one instance.

Implemented types

Constructors

RecordingHandler({Level minLevel = Level.trace})
Creates a handler. minLevel drops records before handle is even called. The default keeps every level.

Properties

count → int
How many records have been kept.
no setter
hashCode → int
The hash code for this object.
no setterinherited
minLevel → Level
Records below this level are dropped by isEnabled.
final
records → List<Record>
All kept records, in the order they arrived. The returned list cannot be changed; call clear to empty the handler.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

at(Level level) → Iterable<Record>
Records whose level is exactly level.
atOrAbove(Level level) → Iterable<Record>
Records whose level is at or above level.
clear() → void
Drops every kept record.
close() → Future<void>
Release resources.
override
countAt(Level level) → int
How many records sit exactly at level.
countAtOrAbove(Level level) → int
How many records sit at or above level.
flush() → Future<void>
Flush any buffered output.
override
from(String? name) → Iterable<Record>
Records from a logger with the given name. Pass null to find records from loggers with no name.
handle(Record record) → void
Write a fully processed record.
override
isEnabled(Level level) → bool
Whether this handler wants records at level.
override
messageContaining(Pattern pattern) → Iterable<Record>
Records whose Record.message is matched by pattern. Pass a plain String for substring search, or a RegExp.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
withField(String key) → Iterable<Record>
Records whose Record.fields holds key, regardless of value.
withFieldValue(String key, Object? value) → Iterable<Record>
Records where Record.fields maps key to value. Uses ==.

Operators

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