log - messages with a date on them.
The functions of the module write to standard error, one line each, with the local date in front:
log = import("log")log.Print("listening on {port}") # 2026/07/29 10:13:44 listening on 8080
log.Fatal("cannot open {path}") # the same, then exit(1)SetPrefix puts a word of your own in front of the date, SetOutput sends the lines somewhere else, and New builds a logger writing to a file:
l = log.New(os.Create("run.log"), "worker ")
l.Print("started")
¶Layout = "%Y/%m/%d %H:%M:%S"valuesource
The layout of the date, in the verbs of time.Format. Local time, seconds only: a log line is read by a person, not parsed.
¶New = fn(w, prefix)source
New returns a logger writing to w, which is anything with a Write, with prefix written before the date of every line.
¶Out = wvaluesource
¶Prefix = if prefix == null { "" } else { string(prefix) }valuesource
¶Stamp = truevaluesource
Stamp is what goes in front of a message. Setting it to false turns the date off, for a program whose output is timestamped by something else.
¶Print = fn(msg)source
Print writes one line. The message is a string, so build it with the interpolation of the language: log.Print("got {n} of them").
¶Fatal = fn(msg)source
Fatal writes one line and ends the program with status 1.
¶SetOutput = fn(w)source
SetOutput sends the lines of the module somewhere else, any file or object with a Write.
¶Out = wvaluesource
¶SetPrefix = fn(s)source
SetPrefix puts s in front of every line, before the date.
¶Prefix = string(s)valuesource
¶SetStamp = fn(on)source
SetStamp turns the date in front of every line on or off.