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, no_run
17//! //No run to avoid to pollute the filesystem, yet checked as working
18//! use rsnaker::game_logic::logger::log_configuration::{init_logger, update_log_level, LogLevel};
19//! use tracing::{info, span, Level};
20//! // 1. Initialize the global logger from a TOML configuration file
21//! // (keep the guard alive!). If the file does not exist, defaults are used.
22//! let _guard = init_logger(Some("snake_log_config.toml"));
23//!
24//! info!("This log is visible at Info level.");
25//!
26//! // 2. Change the log level dynamically later in execution
27//! update_log_level(LogLevel::Debug);
28//!
29//! // 3. Using a Span to capture a specific context/timed window
30//! // Creates a new span named "game_session" with a dynamic property
31//! let session_span = span!(Level::INFO, "game_session", session_id = 12345);
32//!
33//! // Enters the span. The context is active until `_enter` goes out of scope.
34//! let _enter = session_span.enter();
35//!
36//! // This log occurs *inside* the span.
37//! // Because our config has `.with_file(true)` and `.with_line_number(true)`,
38//! // the output file will automatically include the filename, line number,
39//! // AND the context: `game_session{session_id=12345}`
40//! info!("Player spawned successfully into the game loop.");
41//!
42//! // The span automatically closes here when `_enter` is dropped.
43//! ```
44//!
45pub mod log_configuration;