Skip to content

feat(observability): centralized admin-tunable event log levels - #106

Merged
ameeribro4-sudo merged 1 commit into
OpenPeerX:mainfrom
emmyoat:observability-log-levels
Jul 19, 2026
Merged

feat(observability): centralized admin-tunable event log levels#106
ameeribro4-sudo merged 1 commit into
OpenPeerX:mainfrom
emmyoat:observability-log-levels

Conversation

@emmyoat

@emmyoat emmyoat commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Closes #95

Summary

Introduces a centralized logging abstraction so mainnet builds get runtime
log-level control instead of the old compile-time-only
#[cfg(feature = "logging")] flag.

  • New src/observability.rs: LogLevel { Debug, Info, Warn, Error } enum
    and log(env, level, topics, data) — the single choke point every
    structured event now routes through.
  • Per-network compiled default (Debug on dev, Info on testnet
    feature, Warn on mainnet feature), overridable at runtime.
  • set_log_level(env, caller, level) — admin-only (require_auth +
    require_admin), durably persisted so it survives calls/upgrades.
    get_log_level(env) added as a companion view.
  • Every helper in events.rs rewritten to call log() with an assigned
    severity. Event names and payloads are unchanged (additive only).
  • The three ad-hoc #[cfg(feature = "logging")] blocks in lib.rs
    (swap, safe_swap) now go through the same runtime-gated log()
    call instead of a compile-time-only flag.
  • README "Observability" section documents levels, per-network defaults,
    the admin override flow, and guidance for adding new events.

Test plan

  • observability_tests.rs covers:
    • set_log_level rejects non-admin callers
    • level persists durably across calls
    • Debug threshold lets all 4 severities through
    • Warn threshold allows only Warn/Error (event-count assertion)
    • Error threshold silences everything except Error-level events
      (event-count assertion, per acceptance criteria)
  • cargo test --workspace --lib

Adds observability::log(env, level, topics, data) as the single choke
point every events.rs helper now routes through, plus a LogLevel enum
(Debug/Info/Warn/Error) with a per-network compiled default (Debug on
dev, Info on testnet via the `testnet` feature, Warn on mainnet via
the `mainnet` feature). The effective threshold is durably overridable
at runtime through the admin-only set_log_level entry point, so a live
mainnet contract can quiet or raise verbosity without a redeploy.

The ad-hoc #[cfg(feature = "logging")] blocks in lib.rs (swap,
safe_swap) are replaced with unconditional calls through the same
log() gate, since compile-time-only flags gave mainnet no runtime
control. Existing event names and payloads are unchanged - only
whether they publish depends on the configured level.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor

Great job consolidating event log levels behind a single admin-tunable knob — much friendlier to operators. CI is green. Clean implementation, merging 🚀

Copy link
Copy Markdown
Contributor

The centralized log-level knob is a clean follow-up — thanks for the work 👋

Heads up: while processing the queue, I merged PRs #101, #102, #103, #104-attempt, #105-attempt, and #110 ahead of yours. This branch edited lib.rs, events.rs, and storage.rs — and so did several of those — so it's now behind main with merge conflicts.

Could you rebase onto the latest main and push? After CI is green on the rebased tip I'll merge it. Ping me if you want a hand.

@ameeribro4-sudo
ameeribro4-sudo merged commit bac9438 into OpenPeerX:main Jul 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PeerX Backlog # 95] Log levels for environments (dev / testnet / mainnet)

3 participants