addSimpleConsoleWithOptions method
Adds a simple console logger with custom formatting options.
The configure callback allows customization of the formatter options.
LoggerFactory.create(
(builder) => builder
..addSimpleConsoleWithOptions((options) {
options
..colorBehavior = LoggerColorBehavior.enabled
..timestampFormat = 'timestamp'
// Single-line output is easier to scan in dense terminal logs.
..singleLine = true
..includeScopes = false;
})
..addFilter(level: LogLevel.information),
).createLogger('CustomSimple')
..logInformation('Single line format with timestamp')
..logWarning('Warnings are easier to spot with colors')
..logError('Errors stand out with bright red');
Implementation
LoggingBuilder addSimpleConsoleWithOptions(
void Function(SimpleConsoleFormatterOptions) configure,
) {
final options = SimpleConsoleFormatterOptions();
configure(options);
final formatter = SimpleConsoleFormatter(options);
services.tryAddIterable(
ServiceDescriptor.singleton<LoggerProvider>(
(sp) => FormattedConsoleLoggerProvider(formatter),
),
);
return this;
}