Mountain/Binary/Initialize/LogLevel.rs
1//! # LogLevel
2//!
3//! Resolves the logging level for the application.
4//!
5//! ## RESPONSIBILITIES
6//!
7//! ### Log Level Resolution
8//! - Read RUST_LOG environment variable
9//! - Apply default log level based on build type
10//! - Resolve final log level for logging initialization
11//!
12//! ## ARCHITECTURAL ROLE
13//!
14//! ### Position in Mountain
15//! - Early initialization component in Binary subsystem
16//! - Provides log level configuration
17//!
18//! ### Dependencies
19//! - log: Logging framework
20//! - std::env: Environment variable access
21//!
22//! ### Dependents
23//! - Fn() main entry point: Uses resolved log level
24//!
25//! ## SECURITY
26//!
27//! ### Considerations
28//! - No security impact (logging only)
29//!
30//! ## PERFORMANCE
31//!
32//! ### Considerations
33//! - Log level resolution is fast
34//! - Correct log level reduces logging overhead
35
36use log::LevelFilter;
37
38/// Resolve the application log level.
39///
40/// Resolves the log level from the RUST_LOG environment variable,
41/// falling back to platform-appropriate defaults.
42///
43/// # Returns
44///
45/// Returns the resolved log level.
46pub fn Resolve() -> LevelFilter {
47 let EnvLogLevel = std::env::var("RUST_LOG").ok().and_then(|s| s.parse::<LevelFilter>().ok());
48
49 let DefaultLogLevel = if cfg!(debug_assertions) { LevelFilter::Debug } else { LevelFilter::Info };
50
51 EnvLogLevel.unwrap_or(DefaultLogLevel)
52}
53
54/// Get the default log level for the current build type.
55///
56/// Returns the default log level based on whether this is a debug
57/// or release build.
58///
59/// # Returns
60///
61/// Returns the default log level.
62pub fn GetDefault() -> LevelFilter { if cfg!(debug_assertions) { LevelFilter::Debug } else { LevelFilter::Info } }