Skip to content

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.log

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.

import std.log
k := "k1"
n := 1
log.set_level("debug") // trace < debug < info < warn < error
println(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, idempotent
import std.log
s := log.span_begin("request") // returns span handle
// ... work ...
micros := s.end() // elapsed microseconds (int)
s.end() // idempotent: second call returns 0
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
}

11 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.

Function Signature Description
std.log.debug debug(msg: str) -> unit Debug
std.log.error error(msg: str) -> unit Error
std.log.get_level get_level() -> str Current level name
std.log.info info(msg: str) -> unit Info
std.log.set_format set_format(name: str) -> bool json or text
std.log.set_level set_level(name: str) -> bool Set level
std.log.span_begin span_begin(name: str) -> span Begin span (opaque handle)
std.log.to_file to_file(path: str) -> bool Sink to file
std.log.to_stderr to_stderr() -> unit Sink to stderr
std.log.trace trace(msg: str) -> unit Trace
std.log.warn warn(msg: str) -> unit Warn
  • 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