createCliLogger function
CliLogger
createCliLogger({
- WriteStream? stderr,
- WriteStream? stdout,
- String? tag,
- ColorTheme? color,
- Symbols? symbols,
- Spinner createSpinner(
- WriteStream stream,
- String text
Build a logger with optional stream overrides and optional prefix tag.
Tag is only cosmetic and prepends a dim "tag" prefix to every output
line. The optional color/symbols/createSpinner overrides are the DI
seams replacing the vitest module mocks of ./theme.ts and
./spinner.ts.
Implementation
CliLogger createCliLogger({
WriteStream? stderr,
WriteStream? stdout,
String? tag,
ColorTheme? color,
Symbols? symbols,
Spinner Function(WriteStream stream, String text)? createSpinner,
}) {
// Default to process streams when callers don't pass explicit destination
// streams.
final stdoutStream = stdout ?? StdioWriteStream(io.stdout);
final stderrStream = stderr ?? StdioWriteStream(io.stderr);
final prefix = tag == null ? '' : pc.dim('[$tag] ');
// Core logger surface used across commands; each method formats
// consistently.
return _CliLogger(
stdout: stdoutStream,
stderr: stderrStream,
prefix: prefix,
color: color ?? _defaultColorTheme(),
symbols: symbols ?? SYMBOLS,
createSpinnerFn: createSpinner ?? _defaultCreateSpinner,
);
}