feat(stdlib): add Log.* — levelled, structured logging (#15)
All checks were successful
docs / build-and-deploy (push) Successful in 2s
All checks were successful
docs / build-and-deploy (push) Successful in 2s
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>
This commit is contained in:
parent
a4f1494a04
commit
031b138f84
17 changed files with 11166 additions and 10404 deletions
24
docs/language/log/log-level.md
Normal file
24
docs/language/log/log-level.md
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
id: log-level
|
||||
name: Log.level
|
||||
category: log
|
||||
kind: namespace-method
|
||||
tokens: Log.level
|
||||
sig: Log.level() -> int
|
||||
tip: The current logging threshold.
|
||||
order: 7
|
||||
ns: Log
|
||||
member: level
|
||||
---
|
||||
|
||||
Returns the current logging threshold — the minimum level that <a href="log-set_level"><code>Log.set_level</code></a> last set (0 by default). Use it to branch on how verbose logging is: skip building an expensive debug string when it would be dropped anyway, or show an in-game indicator that verbose logging is on. The levels are <code>trace</code> 0 through <code>error</code> 4.
|
||||
|
||||
```ludic
|
||||
program Level {
|
||||
entry {
|
||||
print(Log.level()) # 0
|
||||
Log.set_level(2)
|
||||
print(Log.level()) # 2
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue