defaultFormatter property
Default log message formatter. Formats the log message with timestamp, level, scope, message, and exception if present.
example:
[2024-06-01T12:00:00.000Z] [SHOUT] [App] This is a log message
Exception: SomeException
Implementation
static LoggerFormatter defaultFormatter =
(LogContext context, LoggerDateFormatter? dateFormatter) {
final buffer = IndentingStringBuffer();
final now = context.timestamp;
final timeString = dateFormatter != null
? dateFormatter(now)
: defaultDateFormatter(now);
buffer.writeRaw(timeString);
buffer.writeRaw(' [${context.level.name}]');
buffer.writeRaw(' [${context.scope}]');
buffer.writeRaw(' ${context.message}');
if (context.throwable != null || context.stackTrace != null) {
buffer.newLine();
buffer.indent();
if (context.throwable != null) {
if (context.throwable is Exception) {
buffer.writeBlock(
'\x1B[31mException: ${context.throwable}\x1B[0m',
);
} else {
buffer.writeBlock('\x1B[31mError: ${context.throwable}\x1B[0m');
}
}
if (context.stackTrace != null) {
buffer.writeLine('StackTrace:');
buffer.writeBlock(Trace.from(context.stackTrace!).terse.toString());
}
buffer.outdent();
}
return buffer.toString();
};