Skip to main content

Maintain/Eliminate/
Logger.rs

1//=============================================================================//
2// File Path: Element/Maintain/Source/Eliminate/Logger.rs
3//=============================================================================//
4// Module: Logger - Logging initialisation for the Eliminate module
5//=============================================================================//
6
7use colored::Colorize;
8
9/// Initialise `env_logger` with a coloured, human-readable format.
10/// Reads `RUST_LOG`; defaults to `info` when the variable is absent.
11pub fn Logger() {
12	env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
13		.format(|Buf, Record| {
14			use std::io::Write;
15
16			let Level = match Record.level() {
17				log::Level::Error => "ERROR".red().bold().to_string(),
18				log::Level::Warn => "WARN ".yellow().bold().to_string(),
19				log::Level::Info => "INFO ".green().to_string(),
20				log::Level::Debug => "DEBUG".cyan().to_string(),
21				log::Level::Trace => "TRACE".dimmed().to_string(),
22			};
23
24			writeln!(Buf, "[{}] {}", Level, Record.args())
25		})
26		.init();
27}