code wiki / (root) / log.nx

log.nx

buildroot/runtime/log.nx

4561 B141 linesdepth 4pulls 4 transitivereach 0 importersview sourcekind tooltopic log
docsdependenciesstructsconstsfunctions

about

log.nx -- structured logging with levels. Five-level hierarchy (TRACE < DEBUG < INFO < WARN < ERROR). Output goes to stderr (fd 2) so stdout stays clean for pipe/ redirect workflows. Each line is prefixed with a level tag + RFC 3339 timestamp + caller-supplied module name. Format: [LEVEL] <timestamp> <module>: <message> e.g. [INFO] 2026-04-21T10:30:42Z http: serving / (200) Used by: any service that needs operational visibility without pulling in a real logging framework. Pairs with timefmt.nx for the timestamp. Invariants: L1 Output is line-oriented (one line per call); LF appended even if caller's message lacks one. L2 Below-threshold calls are CHEAP -- short-circuit early before any formatting work. L3 Multi-thread safe at the SYSCALL level (sys_write is atomic up to PIPE_BUF on POSIX); concurrent log calls never interleave at the byte level for short lines. L4 No allocations on the hot path; uses a single sys_mmap buffer reused across calls.

dependencies 2 imports · 0 importers

syscalls.nx timefmt.nx log.nx

imports: syscalls.nxtimefmt.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main log_msg log_write log_append log_level_tag format_rfc3339 break_down_utc civil_from_days emit_zpad log_append_bytes

structs

none

consts

30const LOG_TRACE: i64 = 0
31const LOG_DEBUG: i64 = 1
32const LOG_INFO: i64 = 2
33const LOG_WARN: i64 = 3
34const LOG_ERROR: i64 = 4

functions

37func log_threshold_slot() -> *i64 {
51func log_level_tag(level: i64) -> *u8 {
called by 1: log_write
61func log_append(buf: *u8, pos: *i64, cap: i64, s: *u8) -> i64 {
called by 1: log_write
74func log_append_bytes(buf: *u8, pos: *i64, cap: i64, src: *u8, n: i64) -> i64 {
called by 1: log_write
89func log_write(threshold: *i64, level: i64,
126func log_msg(threshold: *i64, level: i64, unix_time: i64,
called by 1: main calls 1: log_write
135func main() -> i64 {
calls 1: log_msg