veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

slog

lib/slog.vk

lib/slog.vk Pure-Veko structured logger supporting .debug, .info, .warn, .error levels, JSON and key=value (kv) output formats, UTC RFC 3339 timestamps (datetime), contextual child loggers (with-fields), automatic <secret> redaction, and pluggable io/Stream or os/stderr sinks.

Logger struct
signature
Logger = struct { level enum = ..., format enum = ..., fields map = ..., use_clock bool = ... }

Immutable structured logger configuration (clone & extend cleanly with with-level / with-fields).

signature
new-json = fn [min_level enum] Logger

Creates a JSON structured logger with the given minimum level (.debug, .info, .warn, .error).

signature
new-kv = fn [min_level enum] Logger

Creates a human-readable key=value (kv) structured logger with the given minimum level.

signature
with-level = fn [lg Logger, min_level enum] Logger

Returns a child logger with an updated minimum log level.

signature
with-fields = fn [lg Logger, extra map] Logger

Returns a child logger with additional contextual key/value fields merged in.

signature
enabled? = fn [lg Logger, lvl enum] bool

Returns true if lvl meets or exceeds lg.level.

signature
format-line = fn [lg Logger, lvl enum, msg str, extra map] str

Formats a single structured log line (without emitting I/O — ideal for testing and custom sinks).

Executable Example
veko
use [slog]
lg = (slog/new-kv .debug) \ struct/with { use_clock = false } \ slog/with-fields { svc = 'api' }
line = slog/format-line lg .info 'ready' { port = 8080 }
if (not (str/contains? line 'level=INFO')) or (not (str/contains? line 'svc=api')) or (not (str/contains? line 'port=8080')) [
  err 'slog format'
] else [ .ok ]
emit fn
signature
emit = fn [lg Logger, lvl enum, msg str, extra map] enum

Emits a structured log line to os/stderr if lvl is enabled on lg.

signature
emit-stream = fn [lg Logger, mut stream io/Stream, lvl enum, msg str, extra map] enum

Emits a structured log line to any io/Stream if lvl is enabled on lg.

signature
debug = fn [lg Logger, msg str, extra map] enum

Convenience level emitters targeting os/stderr.

info fn
signature
info = fn [lg Logger, msg str, extra map] enum
warn fn
signature
warn = fn [lg Logger, msg str, extra map] enum
signature
error = fn [lg Logger, msg str, extra map] enum