Skip to content

std:logging/ColoredFormatter

Canonical occurrence: protos/lib/logging/ColoredFormatter.protos · Protos revision: e99b712ecf658a527b1fe82c8beba2c1286d8dc9.

Human-readable log lines with a colored level. A colored formatter decorates the line of std:logging/TextFormatter, which remains the only definition of the human line grammar: the formatter adds std:text/ANSI foreground sequences around the LEVEL token and changes nothing else.

The fixed palette is TRACE blue, DEBUG cyan, INFO default, WARN yellow, and ERROR red. INFO therefore never generates an escape sequence. Timestamp, message, fields, and the error=true marker are never styled, and control characters in event text stay escaped by TextFormatter, so the only real escape characters in a colored line are the generated sequences.

Whether styling is enabled is decided by the caller. The formatter consults no environment, terminal, Process, or standard stream; a caller whose writer capability changes constructs another formatter. Composition reuses std:logging/TextSink(formatter, writer).

This page lists the complete mechanically observable top-level slot inventory required by D067. Authored documentation, when present, is canonical D062 prose; mechanical presence alone does not create a stability or compatibility promise.

Answers a fresh frozen formatter that styles according to std:text/ColorMode.resolve(mode, autoEnabled), resolved once now. Both arguments are validated as resolve validates them, signalling its Error.

The formatter answers format(event), a String. When styling is disabled it is exactly std:logging/TextFormatter.format(event); when enabled, removing the generated sequences yields exactly that String. Every Error of TextFormatter.format, including for an unrecognized event or an unwritable timestamp, is signalled unchanged.

Exact module source · Standard-library API · Standard library overview