Types
Child logger carrying bound fields; create with log.with. Methods mirror the module surface: logger.info(msg), logger.warn_with(...).
fields: {string: string} | The bound fields, emitted ahead of the per-call fields of every record this logger writes. |
|---|
Functions
Sets the minimum emitted level (debug, info, warn, error). Unknown names are ignored — logging must not take the app down.
std.log.set_level("info")
std.log.set_format("text")
std.log.set_clock_ms(0)
println(std.log.level())
println(std.log.format())
std.log.debug("filtered")
std.log.info("ready")
std.log.warn_with("slow", {"elapsed_ms": "125"})
std.log.error("stopped")
std.log.set_clock_ms(-1)Returns the current minimum level name.
Chooses the output encoding: "json" (the default) or "text".
Unknown names are ignored — logging must not take the app down, which is set_level's rule too. Set once at boot: every call site's output depends on it, which is true of the level as well and is why both live here rather than in an argument nobody would pass.
Text renders <ts> level: msg · key=value key=value, empty values skipped. A field value is already a raw JSON fragment, so it prints as it stands: count=3, file="a.sql".
name: Either"json"or"text"; anything else is ignored.
The current output encoding: "json" or "text".
Fixes the record timestamp (epoch milliseconds, UTC) for deterministic test output; a negative value restores the real clock.
ms: Fixed timestamp in epoch milliseconds (UTC); negative restores the real clock.
Tees every emitted record (after stdout emission) to handler as (level, msg, fields_json) — the seam an error-reporting package attaches to. fields_json is the record's field object without ts/level/msg ({} when there are none).
handler: Called with(level, msg, fields_json)after each record reaches stdout.
fn capture(level: string, message: string, fields: string) {
println(level + ": " + message + " " + fields)
}
fn main() {
std.log.set_handler(capture)
std.log.info_with("built", {"target": "\"moon\""})
std.log.clear_handler()
}Detaches the handler installed by set_handler.
Replaces the default stdout writer with a record callback. Level filtering still happens first; the callback receives (level, message, fields_json) and owns formatting, additional filtering, destination and flushing. Bound and per-call fields have the same representation as set_handler. The independent handler, when installed, runs after this callback returns.
std.log.set_output(|level, message, _fields| println("[" + level + "] " + message))
std.log.info("ready")
std.log.clear_output()Restores stdout output in the format selected by set_format.
Emits a debug-level record.
msg: Message text for the record.
Emits an info-level record.
msg: Message text for the record.
Emits a warn-level record.
msg: Message text for the record.
Emits an error-level record.
msg: Message text for the record.
Emits a debug-level record with fields (values are raw JSON fragments).
msg: Message text for the record.fields: Structured fields; each value is a raw JSON fragment, so a string needs its own quotes.
Emits an info-level record with fields (values are raw JSON fragments).
msg: Message text for the record.fields: Structured fields; each value is a raw JSON fragment, so a string needs its own quotes.
Emits a warn-level record with fields (values are raw JSON fragments).
msg: Message text for the record.fields: Structured fields; each value is a raw JSON fragment, so a string needs its own quotes.
Emits an error-level record with fields (values are raw JSON fragments).
msg: Message text for the record.fields: Structured fields; each value is a raw JSON fragment, so a string needs its own quotes.
Returns a child logger with fields bound; bound fields precede per-call fields in every record the child emits.
fields: Fields bound to the child, ahead of any per-call fields.
let request_log = std.log.with({"request_id": "\"abc123\""})
request_log.debug("received")
request_log.info_with("served", {"status": "200"})
request_log.warn("slow")
request_log.error_with("failed", {"retry": "true"})