prettyLog function
void
prettyLog(})
Prints the contents of a LogRecord
with pretty colors.
By passing omitError
, you can omit printing the error of a given
LogRecord
.
You can also pass a custom printFunction
or logColorChooser
.
Implementation
void prettyLog(LogRecord record,
{bool Function(LogRecord)? omitError,
void Function(String)? printFunction,
AnsiCode Function(Level)? logColorChooser}) {
logColorChooser ??= chooseLogColor;
omitError ??= (_) => false;
printFunction ??= print;
var code = logColorChooser(record.level);
if (record.error == null) printFunction(code.wrap(record.toString())!);
if (record.error != null) {
var err = record.error;
if (omitError(record)) return;
printFunction(code.wrap(record.toString() + '\n')!);
printFunction(code.wrap(err.toString())!);
if (record.stackTrace != null) {
printFunction(code.wrap(record.stackTrace.toString())!);
}
}
}