std/log
Records with a level, a time, a message, and fields of keys and values, written as text or as JSON Lines to standard error, standard output, and files that rotate by size or by time.
import "std/log"
Logger log = logger() // INFO and up, to standard error
log_to_file(log, "app.log", format: "json", max_bytes: 10000000, keep: 3)
log.info("server started", {"port": "8080"})
Logger request = log.with_field("request", "42")
request.warn("slow answer", {"ms": "950"})
// 2026-11-06T16:45:07.123Z WARN slow answer request=42 ms=950| Function or method | Result |
|---|---|
logger(level, format) |
a Logger of records at level and up, LogLevel.INFO unless given, to standard error as "text" or "json" |
quiet_logger(level) |
a Logger that writes nowhere until outputs are added |
log_to_stdout(l, format) |
adds standard output |
log_to_file(l, path, format:, max_bytes:, rotate_every:, keep:, level:) |
adds a file, and gives its LogOutput; max_bytes rotates it before it passes that size, rotate_every when the "hour" or "day" changes, keep is how many old files stay, and level the least level it takes |
l.trace, l.debug, l.info, l.warn, l.error (message, fields) |
a record, with fields from a map[str, str] |
l.with_field(key, value) |
a logger that writes where l does, with the field in each record |
l.enabled(level) |
whether a record at level would be written |
log_on_loop(l), l.flush() |
keep the records and write them after the event loop's current callback, so a callback never waits for a file; flush writes what is kept |
A text record is the time in UTC, the level, the message, and key=value
for each field, in quotes when it has spaces; a JSON record has time,
level, message, and the fields. A file rotated by size becomes
path.1, the one before path.2, and so on; one rotated by time becomes
path.2026-11-06, or path.2026-11-06T13 by the hour.