std.log
The log of a program: lines with the time, a level and a message, on the standard output or error, at the end of a file or both, as text with colors or as JSON for the services.
import std.log
log.info("listening on {}", port) // 2026-11-12T10:03:12.250+01:00 INFO listening on 8080
log.Logger service
service.setLevel(log.Level.Debug) // debug() writes too
service.setFile("service.log") // at the end of that file too
service.setConsole(log.Console.Off) // and no more on the standard output
service.setJson(true) // {"time":"...","level":"INFO","message":"..."}
service.info("started")
log.Logger request = service.with("request", id).withInt("user", 42)
request.warn("slow answer") // ... "message":"slow answer","request":"7f3a","user":42}
The guide: Files, processes and time.
Generata dalla documentazione nei sorgenti della libreria, che è in inglese.
#Tipi
#Level
enum LevelHow much a line of the log matters.
Debug: the details that serve who looks for a problemInfo: what the program does: the level of a logger that is told nothing elseWarn: something to look at, which did not stop the workError: something that failed
#Console
enum ConsoleWhere a logger writes on the terminal of the program.
Output: the standard output: where a logger that is told nothing else writesError: the standard errorOff: nowhere: the lines go to the file alone
#Logger
struct LoggerWrites the lines of a log: to the standard output or error, to a file or to both, from a level on, as text or as JSON, with some fields of its own after the message. One declared without a value writes text to the standard output from Info on, with colors when that is a terminal. It is a value: a copy has what the logger had when it was copied, and is given to the functions and to the tasks that write.
#Logger.setLevel
void setLevel(Level level)The lowest level that the logger writes, Info at the start: the lines below it are not written.
#Logger.setJson
void setJson(bool on)With true the lines are objects of JSON, one for each line, with "time", "level", "message" and the fields of the logger, for the tools that collect the logs; with false they are text again.
#Logger.setConsole
void setConsole(Console where)Where the lines go on the terminal: Console.Output, the standard output, at the start; Console.Error, the standard error; Console.Off, nowhere, for a logger that writes to its file alone.
#Logger.setFile
void setFile(string file)The lines go also at the end of the file at file, created if it does not exist, and with "" to no file again. setConsole(Console.Off) leaves the file alone. The file is opened for each line, so a tool that rotates the logs can move it away at any time: the next line makes a new one. A line that cannot be written to the file goes to the standard error, if the terminal did not have it already.
#Logger.setColor
void setColor(bool on)Whether the lines of text on the terminal have colors, true at the start: the time in grey, DEBUG in blue, INFO in green, WARN in orange and ERROR in red. The colors are written only when the standard output or error is a terminal: one sent to a file or to another program gets the text alone. The lines of JSON have no colors.
#Logger.setTimeFormat
void setTimeFormat(string pattern)How the time of a line is written: a pattern of DateTime.format of std.time, as "%F %T" for 2026-11-12 10:03:12, without the zone, or "%T.%3f" for 10:03:12.250; with "", as at the start, the format of ISO 8601 with the milliseconds and the zone, 2026-11-12T10:03:12.250+01:00. A pattern with a letter that format does not know writes the time of ISO 8601.
#Logger.setFileColor
void setFileColor(bool on)Whether the lines of text in the file have the colors too, false at the start: for a file that is read with a program that shows them, as less -R or tail -f in a terminal.
#Logger.with
Logger with(string key, string value) constA logger as this one, with the field key with the text value too.
#Logger.withInt
Logger withInt(string key, i64 value) constA logger as this one, with the field key with the number value too.
#Logger.debug
void debug(string message) constWrites a line for who looks for a problem, when the level is Debug.
#Logger.info
void info(string message) constWrites a line that says what the program does.
#Logger.warn
void warn(string message) constWrites a line about something to look at.
#Logger.error
void error(string message) constWrites a line about something that failed.
#Funzioni
#info
void info(string message)Writes a line that says what the program does, on the standard output, as a Logger that is told nothing does. The message is a text, or a format with its arguments, as that of println: log.info("{} users", count).
#warn
void warn(string message)Writes a line about something to look at, on the standard output.
#error
void error(string message)Writes a line about something that failed, on the standard output.
#with
Logger with(string key, string value)A logger that writes on the standard output, whose lines have the field key with the text value after the message: the request, the user, the part of the program that writes.
#withInt
Logger withInt(string key, i64 value)A logger that writes on the standard output, whose lines have the field key with the number value.