generated from GarandPLG/rust-flake-template
- Adjust rustfmt.toml to set tab_spaces = 4. - Reformat imports, struct definitions, function bodies, and match arms across the project to match the new style (aligned fields, added spacing, etc.). - Ensure all code complies with the updated rustfmt settings.
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
use simplelog::{Config, LevelFilter, WriteLogger};
|
|
use std::fs::File;
|
|
|
|
/// Initializes the global logger for the application.
|
|
///
|
|
/// This function creates (or truncates) a file called `war_in_tunnels.log`
|
|
/// in the current working directory and configures a `simplelog::WriteLogger`
|
|
/// to write log messages with a minimum level of `Info`.
|
|
///
|
|
/// # Panics
|
|
///
|
|
/// - If the log file cannot be created (e.g., due to permission issues).
|
|
/// - If the logger cannot be initialized (which would indicate an internal
|
|
/// error in the `simplelog` crate).
|
|
///
|
|
/// Call this once, preferably at the very beginning of `main()`, before any
|
|
/// logging macros are used.
|
|
///
|
|
/// # Example
|
|
///
|
|
/// ```
|
|
/// use war_in_tunnels::logs::init_logger;
|
|
/// use log::info;
|
|
///
|
|
/// fn main() {
|
|
/// init_logger();
|
|
/// info!("Application started");
|
|
/// }
|
|
/// ```
|
|
pub fn init_logger() {
|
|
WriteLogger::init(
|
|
LevelFilter::Info,
|
|
Config::default(),
|
|
File::create("war_in_tunnels.log").expect("Failed to create log file"),
|
|
)
|
|
.expect("Failed to initialize logger");
|
|
}
|