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

PuduLangLog.pudu

Pudu75 lines2.8 KB

GitHub ↗
1/** @Log.Root.Vocabulary — levels, captured values, templates, and events */2module PuduLangLog34/** @Log.Level.Scale — how much an event matters, least first */5export type Level = Verbose | Debug | Information | Warning | Error | Fatal67/// Every level, least severe first.8export const LEVELS: Array[Level] = [Verbose, Debug, Information, Warning, Error, Fatal]910/** @Log.Timestamp.Instant — a UTC moment and its observer's offset */11export type Timestamp = { millis: Int, offset: Int }1213/** @Log.Scalar.Atom — one indivisible captured value */14export type Scalar = Null | Boolean(Bool) | Integer(Int) | Real(Float64) | Exact(Decimal) | Text(Str) | Moment(Timestamp) | Span(Int) | Binary(Bytes)1516/** @Log.Value.Captured — a property value as the pipeline carries it */17export type Value = Scalar(Scalar) | Sequence(Array[Value]) | Structure(Structure) | Dictionary(Array[Entry])1819/** @Log.Structure.Record — named properties under an optional type tag */20export type Structure = { tag: Option[Str], properties: Array[Property] }2122/** @Log.Entry.Pair — one dictionary key and its value */23export type Entry = { key: Scalar, value: Value }2425/** @Log.Property.Named — a name bound to a captured value */26export type Property = { name: Str, value: Value }2728/** @Log.Hint.Capture — how a hole captures its argument */29export type Hint = Default | Destructure | Stringify3031/** @Log.Alignment.Padding — the width and side of padding */32export type Alignment = { left: Bool, width: Int }3334/** @Log.Hole.Token — one property placeholder in a template */35export type Hole = {36  name: Str,37  raw: Str,38  format: Option[Str],39  alignment: Option[Alignment],40  hint: Hint,41  position: Option[Int]42}4344/** @Log.Token.Piece — literal text or a placeholder */45export type Token = Literal(Str) | Placeholder(Hole)4647/** @Log.Binding.Mode — how holes take their arguments */48export type Binding = Unbound | Named | Positional4950/** @Log.Template.Parsed — a message template and its tokens */51export type Template = { text: Str, tokens: Array[Token], holes: Array[Hole], binding: Binding }5253/** @Log.Failure.Error — an error value attached to an event */54export type Failure = { kind: Str, message: Str, trace: Array[Str], causes: Array[Failure] }5556/** @Log.Event.Record — one log event as sinks receive it */57export type Event = {58  timestamp: Timestamp,59  level: Level,60  template: Template,61  properties: Array[Property],62  failure: Option[Failure],63  traceId: Option[Str],64  spanId: Option[Str]65}6667/** @Log.RollingInterval.Period — how often a file sink starts afresh */68export type RollingInterval = Infinite | Year | Month | Day | Hour | Minute6970/// Every rolling interval, longest first.71export const ROLLING_INTERVALS: Array[RollingInterval] = [Infinite, Year, Month, Day, Hour, Minute]7273/** @Log.Formatter.Text — renders an event as text */74export type Formatter = fn(&Event) -> Str75