8 Commits
Author SHA1 Message Date
aydencharles dee1c1d523 feat(log): share the file sink and cap rotation from config 2026-10-02 16:40:23 +08:00
Hexwell d30c9c2eac fix(crash): preserve logs and point reports to GitHub 2026-08-21 23:54:54 +08:00
Hexwell 9a9c37e318 feat(logging): add runtime levels and log rotation 2026-08-06 18:12:52 +08:00
Hexwell c88b173f34 fix(log): keep daemon log files reachable 2026-07-30 23:11:11 +08:00
HexwellandClaude Fable 5 7e64b92d98 refactor(log): route every call site through the shared logger
There were seven ways to log, each invented where the previous one was not
reachable:

  OnionHEN_log   libonion_platform, the only one with a file sink
  shellui_log    libonion_ipc, klog only — because it did not depend on
                 libonion_platform
  game_log       same body as shellui_log
  onion_ipc_log  same body again
  logf           libonion_ipc's IPC server, with a sink the host had to
                 register
  log_msg        onion_elfldr_server
  crash_log      util's fault handler, plus a second copy in common/
  boot_log       bootstrapper's fault handler
  klog_printf / klog_puts / printf / puts, called directly

A message's destination therefore depended on which module happened to emit
it: ShellUI's ~300 records went to volatile klog and never reached a log file,
while the daemon's went to klog, stdout and disk.

Everything now goes through the LOG_* macros. All seven legacy entry points
are gone, and klog_printf survives only as a sink inside log.c.

The bare -nostdlib libraries deliberately did not get their own backend. Those
flags only affect the static library's own link step; each is linked into a
host with full libc and pthread, which is why they already called vsnprintf.
A second backend would have recreated the split this removes.

Levels were inferred from message text rather than applied uniformly — the old
entry points carried no severity, so a blanket mapping would either bury real
failures at debug or promote routine chatter to error. Result: 291 error, 63
warn, 140 info, 309 debug.

Consequences worth noting:

  * ShellUI records now reach the log file, so a user report finally contains
    what the injected process did. In release builds most of them are debug
    and compile out, so this costs nothing on a retail unit.
  * The IPC server's log-sink injection is gone; both servers registered the
    same forwarder.
  * common/backtrace.cpp and backtrace.hpp are deleted. That was a third copy
    of the frame walking plus its own crash_log, and every caller of
    printBacktrace/printBacktraceForCrash had already been commented out.
  * Fault handlers use onion_log_emergency, so crash records go to the same
    file as everything else instead of a separate crash log.

The shared entry point carries a printf format attribute, which the old
shellui_log explicitly avoided. That attribute found seven real format
defects: %p given typed pointers, %lx given a MonoObject*, %p given a
uint64_t, and %u given an unsigned long. Four of them only compile in debug
builds, so they had gone unnoticed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-26 21:10:08 +08:00
HexwellandClaude Fable 5 e5f937be0b feat(log): add levels, rotation and thread safety
OnionHEN_log wrote unconditionally to klog, stdout and a file: no level, no
size bound, no locking, and an open/write/close per record. Release builds
therefore logged exactly as much as debug builds, and the file grew without
limit on a console the user cannot easily clean out.

Add ERROR/WARN/INFO/DEBUG/TRACE behind two gates. ONION_LOG_COMPILE_LEVEL is
checked first and is a constant expression, so a level compiled out costs
nothing at all — the arguments are never evaluated, which matters for the
LOG_TRACE sites that format state. onion_log_set_level then allows raising
verbosity at runtime for a bug report.

Runtime behaviour:
  * one mutex around the three sinks so records never interleave, with
    formatting kept outside it — the daemon logs from five threads
  * the file sink rotates at a size cap, keeping one previous generation
  * the descriptor stays open instead of reopening per record
  * a monotonic timestamp and the level are prefixed to every record
  * exactly one trailing newline regardless of what the caller passed

onion_log_emergency is the fault-handler path: it formats on the stack and
writes without locking, since the faulting thread may already hold the log
lock, and it bypasses both gates because a crash is always worth recording.

OnionHEN_log keeps its name and maps to INFO. Its ~600 call sites predate
levels and are mostly lifecycle reporting, so demoting them wholesale would
empty out a release log.

The test Makefile now emits and consumes depfiles: editing onion/log.h
previously reused a stale log.o, which reported a failure the source no
longer had.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-26 20:44:14 +08:00
Hexwell aad2cdaabc refactor: rebrand OrionHEN to OnionHEN
Rename product, namespaces, libraries, paths, and assets from Orion/orion
to Onion/onion across the tree. TCP stack-shutdown magic is now ONIO
(0x4F4E494F) to match the corrected branding.
2026-07-15 18:23:16 +08:00
Hexwell 2c455c1eb6 test: expand host unit coverage for platform, ready flags, and IPC
Add suites for liborion_platform (fs/log/notify), richer settings and ready
flag cases, and msg.hpp protocol ordinals. Link real platform sources under
ORION_HOST_TEST; fix DaemonCommands to unsigned so high-bit opcodes are
well-formed. Rename host binary to orion-host-tests.
2026-07-10 15:42:32 +08:00