write<TState> method
void
write<TState>({
- required LogEntry<
TState> logEntry, - ExternalScopeProvider? scopeProvider,
- required StringBuffer textWriter,
override
Writes the log message to the specified StringBuffer.
Implementations can use ANSI color codes in the output for console coloring.
Implementation
@override
void write<TState>({
required LogEntry<TState> logEntry,
ExternalScopeProvider? scopeProvider,
required StringBuffer textWriter,
}) {
final message = logEntry.formatter(logEntry.state, logEntry.exception);
if (message.isEmpty && logEntry.exception == null) {
return;
}
// Write systemd priority (syslog severity)
final priority = _getSystemdPriority(logEntry.logLevel);
textWriter.write('<$priority>');
// Write timestamp if configured
if (_options.timestampFormat != null) {
final dateTime = _options.useUtcTimestamp
? DateTime.now().toUtc()
: DateTime.now();
textWriter
..write(_formatTimestamp(dateTime))
..write(' ');
}
// Write category and event ID
textWriter
..write(logEntry.category)
..write('[')
..write(logEntry.eventId.id)
..write('] ');
// Write scopes if enabled
if (_options.includeScopes && scopeProvider != null) {
scopeProvider.forEachScope<Object?>((scope, _) {
textWriter
..write(scope)
..write(' => ');
}, null);
}
// Write message
if (message.isNotEmpty) {
textWriter.write(message);
}
// Write exception if present
if (logEntry.exception != null) {
textWriter
..write(' ')
..write(logEntry.exception.toString());
}
}