code wiki / (root) / nx_log.nx

nx_log.nx

buildroot/runtime/nx_log.nx

11162 B320 linesdepth 3pulls 3 transitivereach 33 importersview sourcekind tooltopic log
docsdependenciesstructsconstsfunctions

about

nx_log.nx -- structured logging framework. Enterprise-grade replacement for ad-hoc `sys_write(2, "tag"...)`. Design draws from: Google glog / Abseil LOG(INFO) Rust tracing crate (levels, spans, structured fields) Microsoft ETW (schema-typed events, high-throughput capture) syslog RFC 5424 (level taxonomy, tag conventions) OpenTelemetry logs data model (severity + body + attributes) What enterprise-grade means here: * Levels -- TRACE/DEBUG/INFO/WARN/ERROR/FATAL. Compile-time AND runtime gated; call sites below min_level compile to a no-op branch, runtime filters emit to fd or drop. * Tags -- every event carries a module-identifier tag for grep / filter / routing. Mandatory, not optional. * Structured output -- each line is '<seq> <level> <tag> <msg>\n' stable format, greppable, machine-parseable. No ANSI escapes, no timestamps that change builds, no env-specific formatting: F6-reproducible. * Deterministic by default -- monotonic sequence counter, not wall-clock time. Tests can snapshot logs byte-for-byte. * Context object -- multiple logger instances can coexist (e.g., parser log, codegen log, test log). Default global context routes to stderr. * Fatal path -- nx_log_fatal exits with NX_ASSERT_EXIT=200, same code as nx_assert so harnesses handle uniformly. Not yet (staged for follow-ups): * Binary encoding option (ETW-style schema-typed events) * Ring buffer capture + post-mortem dump * Span / scope tracking (entry/exit markers with id) * Field name = value pairs (structured attributes) * Remote sink via socket / shared ring These ship in nx_log_span.nx + nx_log_sink.nx when needed.

dependencies 1 imports · 32 importers

syscalls.nx nx_log.nx _min2.nx nx_atomic_intrinsic_test.nx nx_chan_mpmc_test.nx nx_dot_simd_demo.nx nx_hw_simd_caps_test.nx nx_log_gate.nx nx_log_v2.nx nx_log_v2_test.nx nx_mutex_race_test.nx nx_net_chan_blob_test.nx

diagram shows first 10 each side; +0 more imports, +22 more importers in the complete lists below.

imports: syscalls.nx

imported by: _min2.nxnx_atomic_intrinsic_test.nxnx_chan_mpmc_test.nxnx_dot_simd_demo.nxnx_hw_simd_caps_test.nxnx_log_gate.nxnx_log_v2.nxnx_log_v2_test.nxnx_mutex_race_test.nxnx_net_chan_blob_test.nxnx_net_chan_test.nxnx_panic.nxnx_parallel_simd_reduce.nxnx_parallel_test.nxnx_pipeline_test.nxnx_remote_worker_test.nxnx_rpc_test.nxnx_simd_bench.nxnx_simd_i16x16_test.nxnx_simd_i32x8_test.nxnx_simd_i8x32_test.nxnx_simd_minmax_test.nxnx_simd_sat_test.nxnx_simd_usat_shift_test.nxnx_simd_vdot_test.nxnx_socket_pingpong_test.nxnx_sum_bench.nxnx_sum_bench_all.nxnx_task_graph_test.nxnx_thread_pool_test.nxnx_thread_spawn_test.nxnx_trace.nx

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

main nx_log_new nx_log_emit ipow10 nx_log_puts nx_log_level_name nx_log_level_name ↻ ipow10 ↻ nx_log_append_i nx_log_puti

structs

74struct NxLogContext

consts

47const NX_MAGIC_10000000: i64 = 10000000
51const NX_LOG_TRACE: i64 = 0 // ultra-verbose, per-instruction tracing
52const NX_LOG_DEBUG: i64 = 1 // diagnostic, devs-only
53const NX_LOG_INFO: i64 = 2 // normal operational events
54const NX_LOG_WARN: i64 = 3 // unexpected but recoverable
55const NX_LOG_ERROR: i64 = 4 // failure, caller should handle
56const NX_LOG_FATAL: i64 = 5 // panic + exit
59const NX_LOG_EXIT: i64 = 200
81const NX_LOG_CTX_BYTES: i64 = 32

functions

85func nx_log_puts(fd: i64, s: *u8) -> i64;
86func nx_log_puti(fd: i64, v: i64) -> i64;
called by 1: nx_log_append_i
87func nx_log_level_name(lvl: i64) -> *u8;
called by 2: nx_log_emitmain
88func ipow10(n: i64) -> i64;
called by 2: nx_log_emitmain
89func nx_log_new(min_level: i64, out_fd: i64) -> *NxLogContext;
called by 2: nx_log_globalmain
98func nx_log_new(min_level: i64, out_fd: i64) -> *NxLogContext
called by 2: mainmain
111func nx_log_global() -> *NxLogContext
129func nx_log_puts(fd: i64, s: *u8) -> i64
136func nx_log_puti(fd: i64, v: i64) -> i64
164func nx_log_level_name(lvl: i64) -> *u8
called by 1: main
182func nx_log_emit(ctx: *NxLogContext, level: i64,
213func ipow10(n: i64) -> i64
228func nx_log_trace(tag: *u8, msg: *u8) -> i64
233func nx_log_debug(tag: *u8, msg: *u8) -> i64
238func nx_log_info(tag: *u8, msg: *u8) -> i64
243func nx_log_warn(tag: *u8, msg: *u8) -> i64
248func nx_log_error(tag: *u8, msg: *u8) -> i64
253func nx_log_fatal(tag: *u8, msg: *u8) -> i64
called by 1: nx_panic calls 2: nx_log_emitnx_log_global
266func nx_log_append_i(ctx: *NxLogContext, v: i64) -> i64
called by 1: main calls 1: nx_log_puti
272func nx_log_append_s(ctx: *NxLogContext, s: *u8) -> i64
calls 1: nx_log_puts
280func main() -> i64