code wiki / (root) / nx_log_v1.nx

nx_log_v1.nx

buildroot/runtime/nx_log_v1.nx

4810 B148 linesdepth 3pulls 3 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

nx_syscalls.nx nx_timefmt.nx nx_log_v1.nx

imports: nx_syscalls.nxnx_timefmt.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap log_msg log_write sys_mmap ↻ log_append log_level_tag format_rfc3339 sys_mmap ↻ break_down_utc civil_from_days emit_zpad log_append_bytes sys_write

structs

none

consts

35const LOG_MAGIC_1024: i64 = 1024
37const LOG_TRACE: i64 = 0
38const LOG_DEBUG: i64 = 1
39const LOG_INFO: i64 = 2
40const LOG_WARN: i64 = 3
41const LOG_ERROR: i64 = 4

functions

44func log_threshold_slot() -> *i64
calls 1: sys_mmap
58func log_level_tag(level: i64) -> *u8
called by 1: log_write
68func log_append(buf: *u8, pos: *i64, cap: i64, s: *u8) -> i64
called by 1: log_write
81func log_append_bytes(buf: *u8, pos: *i64, cap: i64, src: *u8, n: i64) -> i64
called by 1: log_write
96func log_write(threshold: *i64, level: i64,
133func log_msg(threshold: *i64, level: i64, unix_time: i64,
called by 1: main calls 1: log_write
142func main() -> i64
calls 2: sys_mmaplog_msg