Skip to main content

rsnaker/game_logic/logger/
mod.rs

1//! # Dynamic Logging Configuration System
2//!
3//! This module provides an asynchronous, non-blocking logging infrastructure
4//! that can have its logging level dynamically updated at runtime. It is built
5//! on top of the `tracing` ecosystem.
6//!
7//! ## Core Features
8//! - **Non-blocking I/O:** Log events are pushed onto an in-memory ring buffer and written
9//!   to disk by a dedicated background worker thread, ensuring the main application threads
10//!   never stall due to disk writes.
11//! - **Hot Reloading:** The active log level (`INFO`, `DEBUG`, etc.) can be modified on the fly
12//!   without restarting the application, using a global `reload::Handle`.
13//! - **File Rotation:** Uses `tracing_appender` to centralize all application logs into a local file.
14//!
15//! ## Example Usage
16//! ```rust
17//! use rsnaker::game_logic::logger::log_configuration::{init_logger, update_log_level, LogLevel};
18//! use tracing::{info, span, Level};
19//!     // 1. Initialize the global logger from a TOML configuration file
20//!     //    (keep the guard alive!). If the file does not exist, defaults are used.
21//!     let _guard = init_logger(Some("snake_log_config.toml"));
22//!
23//!     info!("This log is visible at Info level.");
24//!
25//!     // 2. Change the log level dynamically later in execution
26//!     update_log_level(LogLevel::Debug);
27//!
28//!     // 3. Using a Span to capture a specific context/timed window
29//!     // Creates a new span named "game_session" with a dynamic property
30//!     let session_span = span!(Level::INFO, "game_session", session_id = 12345);
31//!
32//!     // Enters the span. The context is active until `_enter` goes out of scope.
33//!     let _enter = session_span.enter();
34//!
35//!     // This log occurs *inside* the span.
36//!     // Because our config has `.with_file(true)` and `.with_line_number(true)`,
37//!     // the output file will automatically include the filename, line number,
38//!     // AND the context: `game_session{session_id=12345}`
39//!     info!("Player spawned successfully into the game loop.");
40//!
41//!     // The span automatically closes here when `_enter` is dropped.
42//! ```
43//!
44pub mod log_configuration;