Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-log

Structured event logging for Pudu: message templates, enrichment, filtering, formatting, and sinks

0.1.0Apache-2.01

InstallClose

Console.md

Markdown78 lines2.2 KB

GitHub ↗

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.Sink

Linkage

  • 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

  1. The defaults use the console template and the literate theme, coloured when Std.Term reports colour (not NO_COLOR, not a dumb terminal, or forced by FORCE_COLOR).
  2. A custom formatter, when set, replaces the template and the theme.
  3. Each event's text is written without an added line break, under a lock, to standard output or, from standardErrorFromLevel up, 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_COLOR and FORCE_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]]