Console.md
PuduLangLog.Sinks.Console
type: module path: "@root/src/PuduLangLog/Sinks/Console.pudu" fidelity: Active grammar: "[[grammar/pudu]]" depth_score: 0.6 depth_status: MEDIUM tags: [module, sink] aliases: [PuduLangLog.Sinks.Console]
Purpose
Writes events to the terminal through an output template, coloured by a theme when the terminal takes colour, sending events from a chosen level to standard error.
Interface
Signatures
export type Options = {
outputTemplate: Str,
theme: Theme.Theme,
colored: Bool,
standardErrorFromLevel: Option[Log.Level],
formatter: Option[fn(&Log.Event) -> Str]
}
export fn defaults() -> Options
export fn render(options: &Options, event: &Log.Event) -> Str
export fn toErrors(options: &Options, level: Log.Level) -> Bool
export fn sink(options: Options) -> Sink.SinkLinkage
- Requires: [[src/PuduLangLog]], [[src/PuduLangLog/Constants/Names]], [[src/PuduLangLog/Domain/Levels]], [[src/PuduLangLog/Domain/Output]], [[src/PuduLangLog/Domain/Parser]], [[src/PuduLangLog/Sink]], [[src/PuduLangLog/Sinks/Theme]],
Std.Out,Std.Sync,Std.Term. - Consumed by: package users, settings, and the examples.
Algorithm
- The defaults use the console template and the literate theme, coloured when
Std.Termreports colour (notNO_COLOR, not a dumb terminal, or forced byFORCE_COLOR). - A custom formatter, when set, replaces the template and the theme.
- Each event's text is written without an added line break, under a lock, to standard output or, from
standardErrorFromLevelup, to standard error.
Negative Logic (Prohibited Paths)
- Two threads never interleave the text of their events.
Edge Cases
- With colour off, the text is exactly what the plain text formatter writes.
Depth
DEPTH 0.6 (MEDIUM). Tested by test/PuduLangLog/Sinks/ConsoleTest.
Grill Log
- Q: Why follow
NO_COLORandFORCE_COLOR? A: They are how people and CI systems say what their terminal wants; escape codes in a piped log file are noise. _Rejected:_ always colouring.
Referenced by
[[src/PuduLangLog/_MOC]] · [[src/PuduLangLog/Constants/Names]] · [[src/PuduLangLog/Domain/Output]] · [[src/PuduLangLog/Settings/Registry]] · [[src/PuduLangLog/Sinks/Theme]] · [[subsystems/Sinks]]
