moon-lander-logging

    Structured logging with a bring-your-own logger trait for the Moon-Lander framework

    Download zip
    Author
    Version
    0.17.0
    License
    Apache-2.0
    Last updated
    yesterday
    Downloads
    7K

    #moonrockz/moon-lander-logging

    Structured logging for the Moon-Lander framework, in the style of .NET Microsoft.Extensions.Logging and Serilog. Library code writes events through one trait, Logger, and the application brings the backend that receives them. The module imports nothing except the MoonBit core library, so a library can depend on the logging abstraction and on nothing else. It has the same API on wasm, wasm-gc, js and native, and does no I/O.

    Import the root package with an explicit alias, because the module name has - in it:

    ///|
    import {
    "moonrockz/moon-lander-logging" @logging,
    }

    #The parts

    PartWhat it is
    LoggerThe trait that a backend implements. log gets each event; enabled filters levels and enables each level by default
    LevelTrace, Debug, Information, Warning, Error, Critical, from the lowest to the highest
    LogEventOne immutable event: level, category, template, properties and error
    MessageSegmentOne part of the message: literal Text or a bound Value with its JSON type
    Level methodstrace, debug, info, warn, error and critical on a &Logger
    MemoryLoggerA logger that keeps each event, for tests and examples

    #Bring your own logger

    A backend is one type with one function. This one prints each event with println. A real backend can write to standard error, a file or a service; the pure module leaves that I/O to the application or the host:

    ///|
    struct PrintLogger {}

    ///|
    impl @logging.Logger for PrintLogger with fn log(_self, event) {
    println(event.to_line())
    }

    ///|
    test "bring your own logger" {
    let logger : &@logging.Logger = PrintLogger::{ }
    logger.info("Build started for {Target}", ["wasm"])
    }

    This prints [INF] Build started for wasm. to_line gives the three-letter level code (TRC, DBG, INF, WRN, ERR or CRT), the category and a colon when the event has one, and the message text. An error goes on a second line as error: <text>, with the Show text of the error.

    Library code takes a &Logger and does not know the backend. A test gives it a MemoryLogger and reads the events back:

    ///|
    fn build(logger : &@logging.Logger) -> Unit {
    logger.info("Build started", [])
    logger.warn("Cache is empty", [])
    }

    ///|
    test "read the events of a library function" {
    let memory = @logging.MemoryLogger::new()
    build(memory)
    let levels = memory.events().map(event => event.level)
    assert_eq(levels, [Information, Warning])
    }

    #Message templates

    A message template names its values, as in Serilog. The arguments bind to the holes in order, and the event keeps each value as Json data, not as text. A backend can write the properties as fields, and message renders the text when a backend wants it:

    ///|
    test "a template keeps its values as data" {
    let memory = @logging.MemoryLogger::new()
    let logger : &@logging.Logger = memory
    let path = "src"
    logger.info("Loaded {Count} files from {Path}", [3, Json(path)])
    let event = memory.events()[0]
    assert_eq(event.template, "Loaded {Count} files from {Path}")
    assert_eq(event.properties(), [("Count", 3), ("Path", "src")])
    assert_eq(event.message(), "Loaded 3 files from src")
    }

    A literal is a Json value as it is; another value goes in Json(value). A type with derive(ToJson) becomes a JSON object, so its fields stay separate.

    Template partMeaning
    {Name}A hole. The name holds ASCII letters, digits and _
    {{ and }}A literal { and a literal }
    Any other braceLiteral text, for example an unclosed {Name or an empty {}

    In the message text, a JSON string shows without quotes, and each other value shows as compact JSON, for example {"id":1}. A mismatch never fails and never drops the event:

    CaseResult
    A hole has no argumentNo property; the message keeps the hole text, for example {Target}
    An argument has no holeThe argument is dropped
    One name in two holesEach hole takes its own argument; the message shows the first value in both

    #Message segments

    A renderer that shows values in a different style needs to know which part of the message is literal text and which part is a value. segments gives the message as ordered parts, from the same template parse as message:

    SegmentWhat it holds
    Text(text)Literal text. A hole with no argument stays here as its text, for example {Target}
    Value(name~, value~)A bound hole: its name and its JSON value

    The text of each segment, in order, is equal to the message. A repeated name shows the first value in each of its holes, as in message. The result is a copy, so a change to it does not change the event:

    ///|
    test "the segments of a message" {
    let memory = @logging.MemoryLogger::new()
    (memory : &@logging.Logger).info("Loaded {Count} files from {Path}", [
    3, "src",
    ])
    let event = memory.events()[0]
    let segments = event.segments()
    assert_eq(segments, [
    Text("Loaded "),
    Value(name="Count", value=3),
    Text(" files from "),
    Value(name="Path", value="src"),
    ])
    let text = segments.map(segment => segment.text()).join("")
    assert_eq(text, event.message())
    }

    The formatting package uses the segments to render console text, readable files and JSON Lines. See its guide in formatting/README.mbt.md.

    #Built-in loggers and combinators

    FunctionResult
    null_logger()Enables no level and drops each event
    MemoryLogger::new()Keeps each event; events() gives a copy
    min_level(logger, level)Passes only the events at level or higher that logger enables
    fan_out(loggers)Gives each event to each logger in the list that enables its level
    with_category(logger, name)Sets the category name on each event (innermost wrapper wins)
    filter_rules(logger, rules)Routes events by longest dot-segment category prefix match
    min_level_switch(logger, switch)Filters events through a live LevelSwitch
    filter_switch(logger, switch)Routes events through a live FilterSwitch
    with_property(logger, name, value)Attaches one structured context property to each event
    with_properties(logger, pairs)Attaches structured context properties to each event
    scoped(logger, pairs, body)Runs body with an enriched logger

    Each combinator takes the logger first, so a chain reads from the backend to the code that writes:

    ///|
    test "chain the combinators" {
    let memory = @logging.MemoryLogger::new()
    let logger = memory
    |> @logging.min_level(Information)
    |> @logging.with_category("morphir.build")
    logger.debug("Dropped", [])
    logger.info("Loaded {Count} files", [3])
    let events = memory.events()
    assert_eq(events.length(), 1)
    assert_eq(events[0].category, Some("morphir.build"))
    }

    fan_out sends one event to two backends, each with its own level:

    ///|
    test "two backends with their own levels" {
    let console = @logging.MemoryLogger::new()
    let errors = @logging.MemoryLogger::new()
    let logger = @logging.fan_out([console, @logging.min_level(errors, Error)])
    logger.warn("Disk {Name} is low", ["C"])
    assert_eq(console.events().length(), 1)
    assert_eq(errors.events().length(), 0)
    }

    #Category routing and live switches

    FilterRules pairs a default LevelFilter (AtLeast(level) or Off) with dot-segmented CategoryPrefix overrides. The longest matching prefix wins, and with_category checks enabled_for before parsing templates:

    ///|
    test "route events by category prefix" {
    let memory = @logging.MemoryLogger::new()
    let rules = @logging.FilterRules::new(default=AtLeast(Warning))
    .with_rule(@logging.CategoryPrefix::parse("morphir.build"), AtLeast(Debug))
    .with_rule(@logging.CategoryPrefix::parse("noisy"), Off)
    let root = @logging.filter_rules(memory, rules)
    @logging.with_category(root, "morphir.build.ir").debug("IR pass", [])
    @logging.with_category(root, "noisy.worker").critical("Muted", [])
    assert_eq(memory.events().length(), 1)
    assert_eq(memory.events()[0].category, Some("morphir.build.ir"))
    }

    Use LevelSwitch or FilterSwitch to change thresholds or rules while the process runs; already-created category loggers see updates on their next call:

    ///|
    test "update category rules live through a FilterSwitch" {
    let memory = @logging.MemoryLogger::new()
    let switch = @logging.FilterSwitch::new(
    initial=@logging.FilterRules::from_level(Warning),
    )
    let build = @logging.filter_switch(memory, switch)
    |> @logging.with_category("morphir.build")
    build.trace("Dropped", [])
    switch.set(
    @logging.FilterRules::from_level(Warning).with_rule(
    @logging.CategoryPrefix::parse("morphir.build"),
    AtLeast(Trace),
    ),
    )
    build.trace("Enabled live", [])
    assert_eq(memory.events().length(), 1)
    assert_eq(memory.events()[0].message(), "Enabled live")
    }

    #Context enrichment

    Use with_property, with_properties, or scoped to attach structured context fields to every event emitted through a derived logger. Context is ordered outer-to-inner and stays isolated from template {Hole} interpolation:

    ///|
    test "attach context properties without changing message templates" {
    let memory = @logging.MemoryLogger::new()
    let req = memory
    |> @logging.with_property("Tenant", "acme")
    |> @logging.with_properties([("RequestId", "req-42")])
    @logging.scoped(req, [("Target", "linux")], log => {
    log.info("Building {Target}", ["wasm"])
    })
    let event = memory.events()[0]
    assert_eq(event.message(), "Building wasm")
    assert_eq(event.context(), [
    ("Tenant", "acme"),
    ("RequestId", "req-42"),
    ("Target", "linux"),
    ])
    assert_eq(event.properties(), [("Target", "wasm")])
    }

    #Levels and the level check

    Each level method asks the logger enabled before it builds an event. A backend that implements enabled pays only that one call for a level it does not want:

    ///|
    struct WarningsOnly {
    mut written : Int32
    }

    ///|
    impl @logging.Logger for WarningsOnly with fn enabled(_self, level) {
    level >= Warning
    }

    ///|
    impl @logging.Logger for WarningsOnly with fn log(self, _event) {
    self.written += 1
    }

    ///|
    test "a disabled level builds no event" {
    let backend = WarningsOnly::{ written: 0, }
    let logger : &@logging.Logger = backend
    logger.debug("Not built", [])
    logger.error("Built", [])
    assert_eq(backend.written, 1)
    }

    A log call never fails the code that writes it: log has no error effect, and a backend that can fail handles its own failure.

    #Secrets

    The module writes only the values that a caller gives it. A configuration Secret has no ToJson, so it cannot become a property by accident, and its Show text is redacted. Do not give the text of Secret::expose to a log method: the event keeps it, and each backend can write it. An error goes into a line through its Show text, so the error type decides what the line holds.

    Logger

    pub(open) trait Logger {
    fn enabled(Self, Level) -> Bool = _
    fn enabled_for(Self, String?, Level) -> Bool = _
    fn log(Self, LogEvent) -> Unit
    }

    A receiver of log events: the bring-your-own seam of the logging module.

    An application or an adapter implements log to send events to any backend. Library code takes a &Logger value and does not know the backend. The level methods (info, warn and the others) ask enabled first, and build no event for a level that is not enabled. The default enabled enables each level.

    log has no error effect. A backend that can fail handles its own failure, so a log call never fails the code that writes it.

    FilterError

    pub suberror FilterError {
    InvalidCategoryPrefix(input~ : String, rule~ : CategoryPrefixRule)
    } derive(Eq,
    Debug
    )

    A failure while parsing a logging filter rule.

    FilterError::equal

    fn FilterError::equal(FilterError, FilterError) -> Bool
    automatically derived

    FilterError::message

    fn FilterError::message(self : FilterError) -> String

    Human-readable description naming the input and broken rule.

    FilterError::not_equal

    fn FilterError::not_equal(x : FilterError, y : FilterError) -> Bool
    automatically derived

    FilterError::to_repr

    automatically derived

    CategoryPrefix

    pub struct CategoryPrefix {
    // private fields
    } derive(Compare, Eq, Hash,
    Debug
    )

    A validated dot-separated category prefix, for example morphir.build.

    CategoryPrefix::compare

    automatically derived

    CategoryPrefix::equal

    automatically derived

    CategoryPrefix::hash

    fn CategoryPrefix::hash(self : CategoryPrefix) -> Int
    automatically derived

    CategoryPrefix::hash_combine

    fn CategoryPrefix::hash_combine(CategoryPrefix, Hasher) -> Unit
    automatically derived

    CategoryPrefix::matches

    fn CategoryPrefix::matches(self : CategoryPrefix, category : String) -> Bool

    Whether self matches category either exactly or on a dot segment boundary.

    CategoryPrefix::not_equal

    fn CategoryPrefix::not_equal(x : CategoryPrefix, y : CategoryPrefix) -> Bool
    automatically derived

    CategoryPrefix::op_ge

    fn CategoryPrefix::op_ge(x : CategoryPrefix, y : CategoryPrefix) -> Bool
    automatically derived

    CategoryPrefix::op_gt

    fn CategoryPrefix::op_gt(x : CategoryPrefix, y : CategoryPrefix) -> Bool
    automatically derived

    CategoryPrefix::op_le

    fn CategoryPrefix::op_le(x : CategoryPrefix, y : CategoryPrefix) -> Bool
    automatically derived

    CategoryPrefix::op_lt

    fn CategoryPrefix::op_lt(x : CategoryPrefix, y : CategoryPrefix) -> Bool
    automatically derived

    CategoryPrefix::output

    fn CategoryPrefix::output(self : CategoryPrefix, logger : &Logger) -> Unit

    The prefix text.

    CategoryPrefix::parse

    fn CategoryPrefix::parse(input : String) -> CategoryPrefix raise FilterError

    Parse a dot-separated category prefix. A valid prefix is 1 to 256 printable ASCII characters without whitespace, does not start or end with ., and has no empty .. segment.

    CategoryPrefix::to_repr

    automatically derived

    CategoryPrefix::to_string

    fn CategoryPrefix::to_string(self : CategoryPrefix) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    CategoryPrefixRule

    pub enum CategoryPrefixRule {
    Empty
    TooLong
    LeadingDot
    TrailingDot
    EmptySegment
    InvalidCharacter(Char)
    } derive(Eq,
    Debug
    )

    The rule that a category prefix input broke.

    CategoryPrefixRule::equal

    automatically derived

    CategoryPrefixRule::not_equal

    automatically derived

    CategoryPrefixRule::to_repr

    automatically derived

    FilterRules

    pub struct FilterRules {
    // private fields
    } derive(Eq,
    Debug
    )

    Immutable category filter rules: a default LevelFilter plus dot-segment prefix overrides resolved by longest prefix match.

    FilterRules::allows

    fn FilterRules::allows(self : FilterRules, category : String?, level : Level) -> Bool

    Whether self accepts an event with category and level.

    FilterRules::default_filter

    fn FilterRules::default_filter(self : FilterRules) -> LevelFilter

    The default filter used when an event has no category or matches no prefix.

    FilterRules::equal

    fn FilterRules::equal(FilterRules, FilterRules) -> Bool
    automatically derived

    FilterRules::from_level

    fn FilterRules::from_level(level : Level) -> FilterRules

    Make filter rules with default AtLeast(level) and no category overrides.

    FilterRules::new

    fn FilterRules::new(default? : LevelFilter) -> FilterRules

    Make filter rules with default and no category overrides.

    FilterRules::not_equal

    fn FilterRules::not_equal(x : FilterRules, y : FilterRules) -> Bool
    automatically derived

    FilterRules::off

    Make filter rules with default Off and no category overrides.

    FilterRules::resolve

    fn FilterRules::resolve(self : FilterRules, category : String?) -> LevelFilter

    Resolve the effective LevelFilter for category by longest dot-segment prefix match, falling back to default_filter.

    FilterRules::rules

    The prefix override rules, ordered from longest prefix to shortest prefix.

    FilterRules::to_repr

    automatically derived

    FilterRules::with_rule

    fn FilterRules::with_rule(self : FilterRules, prefix : CategoryPrefix, filter : LevelFilter) -> FilterRules

    Return new filter rules with prefix mapped to filter. Replacing an existing prefix keeps only the latest filter for that prefix.

    FilterSwitch

    pub struct FilterSwitch {
    // private fields
    }

    A mutable handle holding an immutable FilterRules snapshot. Loggers wrapped with filter_switch and sessions bound to the switch observe updates on the next level check and log call without rebuilding derived loggers.

    FilterSwitch::allows

    fn FilterSwitch::allows(self : FilterSwitch, category : String?, level : Level) -> Bool

    Whether the current rules accept an event with category and level.

    FilterSwitch::get

    Read the current FilterRules snapshot.

    FilterSwitch::new

    fn FilterSwitch::new(initial? : FilterRules) -> FilterSwitch

    Make a FilterSwitch initialized to initial.

    FilterSwitch::set

    fn FilterSwitch::set(self : FilterSwitch, next : FilterRules) -> Unit

    Replace the current FilterRules snapshot with next.

    Level

    pub(all) enum Level {
    Trace
    Debug
    Information
    Warning
    Error
    Critical
    } derive(Compare, Eq,
    Debug
    )

    The severity of a log event, from the lowest to the highest, with the names of Microsoft.Extensions.Logging. Levels compare in this order.
    impl Show for Level

    Level::compare

    fn Level::compare(Level, Level) -> Int
    automatically derived

    Level::equal

    fn Level::equal(Level, Level) -> Bool
    automatically derived

    Level::not_equal

    fn Level::not_equal(x : Level, y : Level) -> Bool
    automatically derived

    Level::op_ge

    fn Level::op_ge(x : Level, y : Level) -> Bool
    automatically derived

    Level::op_gt

    fn Level::op_gt(x : Level, y : Level) -> Bool
    automatically derived

    Level::op_le

    fn Level::op_le(x : Level, y : Level) -> Bool
    automatically derived

    Level::op_lt

    fn Level::op_lt(x : Level, y : Level) -> Bool
    automatically derived

    Level::output

    fn Level::output(self : Level, logger : &Logger) -> Unit

    The level name, for example Information.

    Level::to_repr

    automatically derived

    Level::to_string

    fn Level::to_string(self : Level) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    LevelFilter

    pub(all) enum LevelFilter {
    AtLeast(Level)
    Off
    } derive(Eq,
    Debug
    )

    A threshold for filtering log events without adding an unemit-able level to Level. AtLeast(min) accepts events at min or higher; Off rejects every event including Critical.
    impl Show for LevelFilter

    LevelFilter::allows

    fn LevelFilter::allows(self : LevelFilter, level : Level) -> Bool

    Whether self accepts an event at level.

    LevelFilter::default

    fn LevelFilter::default() -> LevelFilter

    The default level filter: AtLeast(Information).

    LevelFilter::equal

    fn LevelFilter::equal(LevelFilter, LevelFilter) -> Bool
    automatically derived

    LevelFilter::not_equal

    fn LevelFilter::not_equal(x : LevelFilter, y : LevelFilter) -> Bool
    automatically derived

    LevelFilter::output

    fn LevelFilter::output(self : LevelFilter, logger : &Logger) -> Unit

    The level filter text: the level name for AtLeast, or "Off".

    LevelFilter::to_repr

    automatically derived

    LevelFilter::to_string

    fn LevelFilter::to_string(self : LevelFilter) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    LevelSwitch

    pub struct LevelSwitch {
    // private fields
    }

    A mutable handle holding a live LevelFilter. Loggers wrapped with min_level_switch read the current threshold on each level check without rebuilding derived loggers.

    LevelSwitch::allows

    fn LevelSwitch::allows(self : LevelSwitch, level : Level) -> Bool

    Whether the current filter accepts level.

    LevelSwitch::get

    Read the current LevelFilter.

    LevelSwitch::new

    fn LevelSwitch::new(initial? : LevelFilter) -> LevelSwitch

    Make a LevelSwitch initialized to initial.

    LevelSwitch::set

    fn LevelSwitch::set(self : LevelSwitch, next : LevelFilter) -> Unit

    Update the current LevelFilter to next.

    LogEvent

    pub struct LogEvent {
    level : Level
    category : String?
    template : String
    error : Error?
    // private fields
    }

    One immutable log event. Code outside this package reads the fields and the properties, but only the level methods of Logger and the combinators of this package make events.

    LogEvent::all_properties

    fn LogEvent::all_properties(self : LogEvent) -> Array[(String,
    Json
    )]

    All structured properties of the event: context properties in outer-to-inner order followed by template-bound properties in hole order. The result is a copy.

    LogEvent::context

    fn LogEvent::context(self : LogEvent) -> Array[(String,
    Json
    )]

    Context properties attached by enrichment wrappers, in outer-to-inner order. The result is a copy: a change to it, or to a JSON array or object in it, does not change the event.

    LogEvent::message

    fn LogEvent::message(self : LogEvent) -> String

    The message text: the template with each hole replaced by the text of its property value. A hole whose name has no property stays as its literal text. When a name occurs in more than one hole, each of them shows the first value.

    LogEvent::properties

    fn LogEvent::properties(self : LogEvent) -> Array[(String,
    Json
    )]

    The values of the template holes as structured data, in hole order. The result is a copy: a change to it, or to a JSON array or object in it, does not change the event.

    LogEvent::property

    fn LogEvent::property(self : LogEvent, name : String) ->
    Json
    ?

    A copy of the value of the property name, or None when the event has no such property. When the name occurs more than one time, the first value is the result.

    LogEvent::segments

    fn LogEvent::segments(self : LogEvent) -> Array[MessageSegment]

    The message as ordered segments. Two literal parts next to each other join into one Text segment. The result is a copy: a change to it, or to a JSON array or object in it, does not change the event.

    LogEvent::to_line

    fn LogEvent::to_line(self : LogEvent) -> String

    The event as text: the level code in brackets, the category and a colon when the event has one, and the message text, for example [INF] morphir.build: Loaded 3 files from src. When the event has an error, a second line error: <text> gives the Show text of the error, so the error type decides what the text holds.

    MemoryLogger

    pub struct MemoryLogger {
    // private fields
    }

    A logger that keeps each event it gets, in the order it gets them. It is for tests and examples: it holds all events in memory and never drops one.

    MemoryLogger::enabled

    fn MemoryLogger::enabled(_self : MemoryLogger, _level : Level) -> Bool

    MemoryLogger::enabled_for

    fn MemoryLogger::enabled_for(self : MemoryLogger, _category : String?, level : Level) -> Bool

    MemoryLogger::events

    fn MemoryLogger::events(self : MemoryLogger) -> Array[LogEvent]

    A copy of the kept events, the first event first.

    MemoryLogger::log

    fn MemoryLogger::log(self : MemoryLogger, event : LogEvent) -> Unit

    Keep event after the events that the logger already holds.

    MemoryLogger::new

    A new in-memory logger with no events.

    MessageSegment

    pub(all) enum MessageSegment {
    Text(String)
    Value(name~ : String, value~ :
    Json
    )
    } derive(Eq,
    Debug
    )

    One ordered part of the message text of an event. A renderer uses the segments to show the literal text and the bound values in different styles. The text of all segments, in order, is equal to LogEvent::message.

    MessageSegment::equal

    automatically derived

    MessageSegment::not_equal

    fn MessageSegment::not_equal(x : MessageSegment, y : MessageSegment) -> Bool
    automatically derived

    MessageSegment::text

    fn MessageSegment::text(self : MessageSegment) -> String

    The text of the segment in the message: the literal text, or the value as message shows it. A JSON string has no quotes, and each other value is compact JSON.

    MessageSegment::to_repr

    automatically derived

    fan_out

    fn fan_out(loggers : Array[&Logger]) -> &Logger

    A logger that sends each event to each of loggers, in list order. It enables a level when one of loggers enables it, and gives each event only to the loggers that enable its level. Later changes to the loggers array do not change the fan-out.

    filter_rules

    fn filter_rules(logger : &Logger, rules : FilterRules) -> &Logger

    Wrap logger with static rules. The wrapper evaluates rules by category and level before forwarding events to logger.

    filter_switch

    fn filter_switch(logger : &Logger, switch : FilterSwitch) -> &Logger

    Wrap logger with a live FilterSwitch. Updates to switch take effect on the next level check and log call for all derived loggers.

    min_level

    fn min_level(logger : &Logger, minimum : Level) -> &Logger

    Wrap logger with a minimum level. The wrapper enables a level only when the level is minimum or higher and logger enables it, and passes only the events of an enabled level to logger.

    min_level_switch

    fn min_level_switch(logger : &Logger, switch : LevelSwitch) -> &Logger

    Wrap logger with a live LevelSwitch. Updates to switch take effect on the next level check and log call.

    null_logger

    fn null_logger() -> &Logger

    A logger that enables no level and drops each event.

    scoped

    fn[T] scoped(logger : &Logger, properties : Array[(String,
    Json
    )], body : (&Logger) -> T raise?) -> T raise?

    Run body with a logger enriched by properties. Preserves whether body raises an error so non-raising callers pay no error effect.

    with_category

    fn with_category(logger : &Logger, name : String) -> &Logger

    Wrap logger with the category name, for example morphir.build. The wrapper checks enabled_for with its category and sets that category on each event that does not already carry one from an inner call-site wrapper.

    with_properties

    fn with_properties(logger : &Logger, properties : Array[(String,
    Json
    )]) -> &Logger

    Wrap logger with structured context properties. All values are deep-copied at wrap time. Context properties stay separate from template hole rendering and are ordered outer-to-inner.

    with_property

    fn with_property(logger : &Logger, name : String, value :
    Json
    ) -> &Logger

    Wrap logger with one structured context property (name, value). The value is deep-copied at wrap time so later mutations do not affect the wrapper. Context properties stay separate from template hole rendering and are ordered outer-to-inner.