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

Failure.pudu

Pudu25 lines1.1 KB

GitHub ↗
1/** @Log.Failure.Builders — error values attached to events */2module PuduLangLog.Failure34import PuduLangLog.Domain.Display as Display5import PuduLangLog as Log67/// A failure of a kind with a message.8export fn of(kind: Str, message: Str) -> Log.Failure { Log.Failure{kind: kind, message: message, trace: [], causes: []} }910/// A failure from any error value: its kind is the given name and its message the value's text.11export fn from[E](kind: Str, error: E) -> Log.Failure {12  let text = show(error)13  let unquoted = if text.length() >= 2 && text.startsWith("\"") && text.endsWith("\"") { text.slice(1, text.length() - 1) } else { text }14  of(kind, unquoted)15}1617/// The failure with trace lines added, innermost call first.18export fn withTrace(problem: &Log.Failure, lines: Array[Str]) -> Log.Failure { Log.Failure{..*problem, trace: problem.trace.concat(lines)} }1920/// The failure with another failure recorded as its cause.21export fn causedBy(problem: &Log.Failure, cause: Log.Failure) -> Log.Failure { Log.Failure{..*problem, causes: problem.causes.push(cause)} }2223/// The failure as text: `Kind: message`, its trace, and its causes.24export fn describe(problem: &Log.Failure) -> Str { Display.failure(problem) }25