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

BridgeTest.pudu

Pudu44 lines2.6 KB

GitHub ↗
1/** @Test.Bridge.Suite — standard library log lines written as events */2module PuduLangLog.BridgeTest34import Std.Io as Io5import Std.List as List6import Std.Log as Standard7import Std.Option as Option8import Std.Test as Test9import PuduLangLog.Bridge as Bridge10import PuduLangLog.Configuration as Configuration11import PuduLangLog.Event as Event12import PuduLangLog as Log13import PuduLangLog.Logger as Logger14import PuduLangLog.Sinks.Memory as Memory15import PuduLangLog.Value as Value1617/// Runs the suite.18fn main() -> Int {19  let memory = Memory.create()20  let logger = Configuration.create().minimumLevel(Log.Debug).overrideLevel("quiet", Log.Error).writeTo(Memory.sink(&memory)).createLogger()21  let standard = Bridge.standard(&logger.withTrace("t1", "s1"))22  let _debug = Standard.debug(&standard, "starting \{up\}")23  let _info = Standard.info(&standard.named("shop.cart").carrying("user", "ada").carrying("SourceContext", "spoofed").carrying(" ", "blank"), "added")24  let _warn = Standard.warn(&standard.named("quiet"), "dropped by the override")25  let _error = Standard.error(&standard.named("quiet"), "kept")26  let _fatal = Standard.fatal(&standard, "down")27  let events = Memory.events(&memory)28  let carted = List.get(&events, 1)29  let checks = Test.suite("Bridge", &[30      Test.equals("messages keep their text, braces included", &Memory.messages(&memory), &["starting \{up\}", "added", "kept", "down"]),31      Test.equals("levels map across", &events.map(|event: Log.Event| event.level), &[Log.Debug, Log.Information, Log.Error, Log.Fatal]),32      Test.equals("the name is the source and fields are properties", &Option.map(carted, |event: Log.Event| event.properties), &Some([Value.property("user", Value.text("ada")), Value.property("SourceContext", Value.text("shop.cart"))])),33      Test.equals("the trace of the logger is kept", &Option.map(carted, |event: Log.Event| (event.traceId, event.spanId)), &Some((Some("t1"), Some("s1")))),34      Test.equals("an unnamed line has no source", &Option.andThen(List.first(&events), |event: Log.Event| Event.sourceContext(&event)), &None),35      Test.equals("level mapping", &[Bridge.levelOf(Standard.Debug), Bridge.levelOf(Standard.Info), Bridge.levelOf(Standard.Warn), Bridge.levelOf(Standard.Error), Bridge.levelOf(Standard.Fatal), Bridge.levelOf(Standard.Silent)], &[Log.Debug, Log.Information, Log.Warning, Log.Error, Log.Fatal, Log.Fatal]),36      Test.that("the standard logger prints nothing itself", Standard.rendered(&standard, Standard.Info, "x").isEmpty())37    ])38  let ran = Test.run(&checks)39  for failure in Test.failuresOf(&ran) {40    let _reported = Io.writeErrorLine(failure)41  }42  Test.report(&ran)43}44