Expand description
High-performance multi-layer logging for the Janus trading system.
§Runtime Log Level Changes
After calling init_logging, use LoggingGuard::create_controller to
obtain a Box<dyn LogLevelController>
that can be installed into JanusState for the API
module to expose as POST /api/log-level.
This module implements the Layered Registry Model described in the Janus Supervisor Architecture Refactor document. It splits logging into two independent pipelines:
-
Layer 1 — Operational Telemetry: Human-readable logs to stdout, filtered by
RUST_LOG/EnvFilter, with runtime-reloadable log levels via a [ReloadHandle]. -
Layer 2 — HFT Data Stream: High-frequency market data events written to a non-blocking rolling file appender. Events are buffered in a ring buffer and flushed by a dedicated worker thread, fully decoupling the latency-sensitive trading path from disk I/O.
§Architecture
┌───────────────────────────────────────────────────┐
│ tracing Registry │
│ │
│ ┌──────────────────────┐ ┌────────────────────┐ │
│ │ Layer 1: Ops/Stdout │ │ Layer 2: HFT File │ │
│ │ EnvFilter (reload) │ │ Targets("janus:: │ │
│ │ fmt::layer().pretty │ │ hft" = TRACE) │ │
│ │ │ │ non_blocking writer │ │
│ └──────────────────────┘ └────────────────────┘ │
└───────────────────────────────────────────────────┘§Critical: WorkerGuard Lifetime
The LoggingGuard returned by init_logging must be held alive
in main() until the very end of the program. Dropping it prematurely
causes the non-blocking HFT writer’s buffer to be discarded, losing
market data audit trail entries during shutdown.
§Usage
use janus_core::logging::{init_logging, LoggingConfig};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let config = LoggingConfig::default();
let guard = init_logging(config)?;
// ... application code ...
// `guard` drops here — HFT buffer is flushed
Ok(())
}Structs§
- Logging
Config - Configuration for the multi-layer logging system.
- Logging
Guard - Holds resources that must outlive the logging system.
Functions§
- init_
logging - Initialize the multi-layer tracing subscriber.