ludic/docs/language/log/log-set_level.md
Orkuncakilkaya 031b138f84
All checks were successful
docs / build-and-deploy (push) Successful in 2s
feat(stdlib): add Log.* — levelled, structured logging (#15)
A Log.* namespace: five levels (trace/debug/info/warn/error), a runtime
threshold, and structured key=value fields, so games get something better than
scattered print calls and release builds can go quiet without touching call
sites.

  - Log.trace/debug/info/warn/error(msg, [k, v]...)  -> stderr, "[LEVEL] msg k=v"
  - Log.set_level(n)   show only level >= n (0 = all default, 5 silences all)
  - Log.level()        read the current threshold

Fields accept strings, ints, and longs (numbers formatted automatically); the
level tag is chosen at compile time so a filtered-out level costs only a
comparison. Writes to stderr, never touching the simulation — no effect on
determinism/replays. v1 is the console sink; rotating-file and in-engine overlay
sinks are noted as follow-ups.

- examples/library/logging.ludic: asserts the set_level/level threshold
  round-trip and that every level (with mixed-type fields) runs without faulting;
  the stderr gating itself was verified by hand (warn/error emit, lower levels
  suppressed). Wired into `x test` (now 53 passed).
- docs: a new Log section + per-symbol pages; inventory and coverage pass.
- seed regenerated; `x bootstrap-cfree` fixpoint holds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 21:57:22 +03:00

1.1 KiB
Raw Permalink Blame History

id name category kind tokens sig tip order ns member
log-set_level Log.set_level log namespace-method Log.set_level Log.set_level(n) -> void Show only messages at level n or above (0 = all). 6 Log set_level

Sets the logging threshold: only messages whose level is n or higher are written; everything below is silently dropped. The levels are trace 0, debug 1, info 2, warn 3, error 4, so set_level(3) shows only warnings and errors, and the default of 0 shows everything. Set it once at startup — low in development, high (3, or 5 to silence all) for release — and every call site adjusts automatically. Read the current value back with Log.level.

Parameters:

  • n — the minimum level to show (0–4; use 5 to silence every level)
program Quiet {
  entry {
    Log.set_level(3)          # warnings and errors only
    Log.info("startup")       # dropped
    Log.warn("low memory")    # shown
  }
}