std.log - ZZ
Leveled logging (trace < debug < info < warn < error), pluggable sinks (stderr, file, json/text format), and timed spans. Span handles are opaque "span".
import std.logPurpose
Section titled “Purpose”std.log provides structured, leveled logging for applications and libraries. Keep hot-path logs at debug and gate expensive field computation behind level checks. Sinks are process-wide — set once in main. Spans nest; end is idempotent.
Quickstart
Section titled “Quickstart”import std.log
k := "k1"n := 1log.set_level("debug") // trace < debug < info < warn < errorprintln(log.get_level())log.set_format("json") // or "text"log.to_stderr()log.to_file("/tmp/app.log")log.trace("tick")log.debug("cache hit {k}")log.info("listening :8080")log.warn("retry {n}")log.error("disk full")
s := log.span_begin("request") // Opaque("span")s.end() // elapsed micros, idempotentSpan lifecycle
Section titled “Span lifecycle”import std.log
s := log.span_begin("request") // returns span handle// ... work ...micros := s.end() // elapsed microseconds (int)s.end() // idempotent: second call returns 0Production patterns
Section titled “Production patterns”import std.log
func main() { log.set_level("info") log.set_format("json") log.to_stderr() log.info("server starting") defer log.span_begin("request").end() // span auto-ends on scope exit}API reference
Section titled “API reference”11 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.
See also
Section titled “See also”std.env— Environment variables and the surrounding host environment.std.args— argv access and the flag parser: booleans, integers, strings and subcommands.std.process— Spawning, waiting on and signalling child processes.std.sys— Infallible machine information: OS, CPU, memory and uptime.std.path— Pure lexical path manipulation: join, split, extension and normalisation.std.cell— Shared mutable slots for lock-free hand-off between green threads.
Full index: API reference · Standard library