log.nx
buildroot/runtime/log.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: syscalls.nxtimefmt.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
| 30 | const LOG_TRACE: i64 = 0 |
| 31 | const LOG_DEBUG: i64 = 1 |
| 32 | const LOG_INFO: i64 = 2 |
| 33 | const LOG_WARN: i64 = 3 |
| 34 | const LOG_ERROR: i64 = 4 |
functions
| 37 | func log_threshold_slot() -> *i64 { |
| 51 | func log_level_tag(level: i64) -> *u8 {
called by 1: log_write |
| 61 | func log_append(buf: *u8, pos: *i64, cap: i64, s: *u8) -> i64 {
called by 1: log_write |
| 74 | func log_append_bytes(buf: *u8, pos: *i64, cap: i64, src: *u8, n: i64) -> i64 {
called by 1: log_write |
| 89 | func log_write(threshold: *i64, level: i64, |
| 126 | func log_msg(threshold: *i64, level: i64, unix_time: i64, |
| 135 | func main() -> i64 {
calls 1: log_msg |