Nimony

The road to Nim 3

logging

nimony/lib/std/logging.nim

This module implements a simple logger. It is a port of Nim's std/logging with one important difference: every log entry is a line of NIF, in NIF's line-based syntax. A log file is therefore a NIF module that NIF tools can read, with the line-based extension enabled (for example nifreader.open(filename, lineBased = true)).

An entry is the level as the tag, followed by the fields of the logger's format string, followed by the message as a string literal:

info "server started"
warn 2026-09-29T09:14:03Z "myapp" "disk almost full"

is the same as the core NIF (info "server started") and (warn "2026-09-29T09:14:03Z" "myapp" "disk almost full").

Format strings ==============

Unlike Nim's logger, the format string is not a free-form prefix but a whitespace separated list of fields; each one becomes a child of the entry. A word that starts with $ is one of the variables below, any other word is emitted as a string literal.

================ ======================================================= Variable Output ================ ======================================================= $date Current date in UTC (2026-09-29) $time Current time in UTC (09:14:03) $datetime $date and $time in ISO 8601 (2026-09-29T09:14:03Z) $app os.getAppFilename() $appname Base name of $app $appdir Directory name of $app $levelid First letter of the log level as an identifier (I) $levelname The log level as an identifier (INFO) ================ =======================================================

Nim's std/times is local time; Nimony's is UTC, hence the Z.

Usage =====

import std/logging

var logger = newConsoleLogger(fmtStr = verboseFmtStr)
addHandler(logger)
info("server started on port ", 8080)

Just like in Nim, the handlers are thread-local: every thread must call addHandler for the loggers it uses.