[M0-CORE-02] Structured logging facade - #2
Merged
Merged
Conversation
The one structured logging facade for the engine (AGENTS §14 LOG-001…LOG-007, FR-12.2): laige-core gains include/laige/logging.h and logging.cpp. Facade: laige::log::Logger — a process-lifetime Meyers singleton that owns its current Sink (unique_ptr). LAIGE_LOG_TRACE/DEBUG/INFO/ WARN/ERROR/FATAL macros put the level gate before argument evaluation, so a disabled event costs exactly one atomic load + branch: no message/field evaluation, no formatting, no allocation, no lock (LOG-003). Gating is an atomic global minimum plus a per-subsystem level table (init-phase mutation, one facade mutex, CONC-001). Fields: scalars render locale-free via std::to_chars into a 64-byte stack buffer; string-like values copy in full; field values must avoid spaces/'=' (the line is '| k=v' machine-parseable, LOG-001). Rate limiting (LOG-004): per (subsystem, event, severity) for Warn/Error/Fatal only. The first event of a key is always recorded (an everEmitted flag — a time_point::min() sentinel overflowed the window subtraction, CPP-004); repeats are counted and reported as a stable 'rate_limited' summary event (event=<orig>, suppressed=N) at window rollover, and pending counts are drained at shutdown. Sinks: ConsoleSink (does not own the stream — stderr must outlive the process) and FileSink (owns the FILE*; create() returns Result<unique_ptr<FileSink>>, open failure = ErrorCode::IoError, the new slot-5 registry code; the LOG-007 minimal fallback keeps the console sink and reports the failure). Fatal records, flushes, and terminates via std::abort() (AGENTS §14 controlled termination). Crash handling: POSIX sigaction (SA_RESETHAND one-shot) for SIGSEGV/ABRT/BUS/FPE/ILL and a vectored SEH handler on Windows — raw write(2) notice, allocation-free try_lock sink flush, re-raise. shutdown() is idempotent (CONC-006): drain summaries, flush, retire (post-shutdown logs discarded). Timestamps: system_clock, UTC RFC 3339, rendered with an in-code Hinnant civil-from-days (no libc date functions). Additive M0-CORE-01 extensions required by this step's FileSink→facade hand-off: Result::takeValue() && (move the success value out of an rvalue result) and ErrorCode::IoError (5), both covered in the result_status suite; docs/api/errors.md documents the new code. Tests: 'logging' CTest entry (27 GTest cases in the shared laige-core_tests executable) — gate semantics, field formatting, both sinks (exact line format, dtor flush, create failure → IoError), rate limiting (suppression, summary after window, window edge, key independence, Warn/Error/Fatal only, opt-out, shutdown drain), Fatal (gate + forked child that emits, flushes, and dies on SIGABRT with the line in the file), crash/shutdown behavior, concurrency (4 threads × 250), and LogPerformance: 100k disabled Trace events → 0 allocations via a test-only global operator new counter (excluded from the sanitizer trees, whose runtimes define their own new/delete — there the same spam loop runs leak-free plus the timing property, the fallback the step names). Measured: disabled ≈46 ns/event vs ≈1207 ns/event enabled (N=200000). Verified locally 2026-09-10 (GCC 16.2.1 static, shared, ASan/UBSan, TSan trees; fresh Clang 22.1.8 static + shared trees): ctest 8/8 and ctest -R logging green in every tree, zero warnings. API contract: docs/api/logging.md. Roadmap: M0-CORE-02 checked with Decision/Verify/Size notes; Progress Board M0 11/22; change log line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
M0-CORE-02 from roadmap/M0-foundations.md: the one structured logging facade (AGENTS §14) in laige-core.
Verified locally: GCC static/shared/ASan/TSan + Clang static/shared — ctest 8/8 and ctest -R logging green in every tree, zero warnings (disabled ≈46 ns/event vs ≈1207 ns/event enabled).