pub fn Logger()Expand description
Sets up the global logger for the application.
This function initializes the env_logger crate with custom formatting
and configuration for the build system. It:
- Reads the
RUST_LOGenvironment variable to set the log level - Defaults to
infolevel if the variable is not set - Provides color-coded output for different log levels
- Formats messages with a consistent
[Build]prefix
§Log Levels
Supported log levels (in increasing verbosity):
error- Only error messageswarn- Warning messages and errorsinfo- Informational messages, warnings, and errors (default)debug- Debug messages and abovetrace- Trace messages and above (very verbose)
§Log Format
Messages are formatted as:
[Build] [LEVEL]: message contentWhere LEVEL is color-coded:
[ERROR]- Red, bold[WARN]- Yellow, bold[INFO]- Green[DEBUG]- Blue[TRACE]- Magenta
§Environment Configuration
The log level is controlled by the RUST_LOG environment variable:
Set minimum log level to debug
export RUST_LOG=debug
Enable debug logs only for the Build module
export RUST_LOG=Build=debug
Enable trace logs for Build::Toml module
export RUST_LOG=Build::Toml=trace§Usage Example
use crate::Maintain::Source::Build::Logger;
use log::{info, error};
// Initialize logger first
Logger();
// Now logging is available throughout the application
info!("Build process started");
error!("Build process failed");§Module-Specific Logging
The build system uses the following logging targets:
Build- General build orchestration messagesBuild::Guard- File backup and restoration messagesBuild::Toml- TOML editing messagesBuild::Json- JavaScriptObjectNotation editing messagesBuild::Exec- Command execution messages
You can set different log levels for each target:
export RUST_LOG=Build=info,Build::Toml=debug,Build::Exec=warn§Thread Safety
The global logger initialized by this function is thread-safe and can be used from multiple threads concurrently without additional synchronization.
§Implementation Notes
This function uses env_logger::Builder to construct the logger with
custom formatting. The formatter uses the colored crate to apply
color coding based on the log level.
The logger is typically called once at program startup, before any other operations that might generate log messages.