nx_log_v1.nx
buildroot/runtime/nx_log_v1.nx
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
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
structs
| none |
consts
| 35 | const LOG_MAGIC_1024: i64 = 1024 |
| 37 | const LOG_TRACE: i64 = 0 |
| 38 | const LOG_DEBUG: i64 = 1 |
| 39 | const LOG_INFO: i64 = 2 |
| 40 | const LOG_WARN: i64 = 3 |
| 41 | const LOG_ERROR: i64 = 4 |
functions
| 44 | func log_threshold_slot() -> *i64 calls 1: sys_mmap |
| 58 | func log_level_tag(level: i64) -> *u8 called by 1: log_write |
| 68 | func log_append(buf: *u8, pos: *i64, cap: i64, s: *u8) -> i64 called by 1: log_write |
| 81 | func log_append_bytes(buf: *u8, pos: *i64, cap: i64, src: *u8, n: i64) -> i64 called by 1: log_write |
| 96 | func log_write(threshold: *i64, level: i64, called by 1: log_msg calls 6: sys_mmaplog_appendlog_level_tagformat_rfc3339log_append_bytessys_write |
| 133 | func log_msg(threshold: *i64, level: i64, unix_time: i64, |
| 142 | func main() -> i64 |