log

The color of the terminal copy of a log line.

In the namespace octomy.

Detailed description

The log handler makes two copies of each line (log-color §LGC-D-1). The sink line goes to the run log and into every diagnostic report, and never holds a color code. The terminal line goes to stderr, and holds 24-bit SGR codes when the run decides on color. This namespace holds what decides it and what the codes are.

A field of the line has a role. The terminal shows a role in a tint of the severity's base color: the base scaled by the role's factor, as the monolith's log does (§LGC-D-3). The GUI log view maps the same roles through the SemanticPalette instead, so that its colors follow the theme.

Type documentation

ColorPolicy enum

enum log::ColorPolicy

Whether the terminal line gets color.

Each constant is in octomy::log::ColorPolicy.

Constant Value Description
Never 0 No color.
Always 1 24-bit color without a test of the terminal, also into a pipe. On Windows only where the console takes virtual terminal codes.
Auto 2 24-bit color only where stderr is a terminal that shows it. The default.

Role enum

enum log::Role

What a part of a log line is.

Each constant is in octomy::log::Role.

Constant Value Description
Severity 0 The severity letter and its colon, such as I:.
Time 1 The timestamp.
Process 2 The executable's name.
Category 3 The category.
File 4 The source file of @file:line.
Line 5 The line number of @file:line.
Function 6 The function.
Punctuation 7 The brackets, the " - " separators, "@" and ":", and the continuation marker.
Message 8 The message body, which keeps the terminal's own color.

Function documentation

appendHighlightedLine

syntax::State log::appendHighlightedLine(QString &out, QStringView line, syntax::Language language, syntax::State state)

Append line to out, with the code of each token of language around it, after a line that ended in state.

Returns the state that the line ends in. A token gets the code of its role's color, then bold or italic as its emphasis says, and ends with ESC[0m, so the text between the tokens keeps the terminal's own color.

colorFor

bool log::colorFor(octomy::log::ColorPolicy policy, bool takesEscapeCodes, bool showsTrueColor, bool windows)

Whether policy colors the terminal line.

Returns false for Never. For Auto, showsTrueColor decides. For Always the answer is true, but on Windows (windows) the console must take the codes, takesEscapeCodes, or the line stays plain.

colorPolicyNamed

std::optional<octomy::log::ColorPolicy> log::colorPolicyNamed(QStringView name)

The policy that name names: never, always or auto.

Returns none for any other text, so that the caller can say what was wrong.

effectiveColorPolicy

octomy::log::ColorPolicy log::effectiveColorPolicy(std::optional<octomy::log::ColorPolicy> option, const platform::terminal::ColorConvention &convention)

The policy of the run, from the inputs of log-color §LGC-D-4 in their order.

Returns option when the command line gave one: the no-color.org FAQ places a per-instance argument over NO_COLOR. Else, from convention, Never when NO_COLOR is set, else Always when CLICOLOR_FORCE is set, else Auto. The first input that applies wins.

highlightedBody

QString log::highlightedBody(QStringView body, syntax::Language language)

body with the code of each token of language around it.

The body is read line by line, a line ending at '\n', and each line starts in the state that the line before ended in. The line breaks stay.

terminalSyntaxColor

octomy::log::Rgb log::terminalSyntaxColor(syntax::Role role)

The terminal's color of the syntax role role.

Returns the color of the dark theme's SemanticPalette::syntax for the role, written down as a constant, because a terminal has no theme to ask (log-color §LGC-D-3).

In this section