A tiny Rust logging crate controlled by the LOG_LEVEL environment variable.
Logging is disabled by default.
Add the crate to your project:
cargo add mini-loguse mini_log::*;
fn main() {
LogMessage::new(Level::Warning, "My Message here");
}By default, this prints nothing.
To enable output, set the LOG_LEVEL environment variable.
LOG_LEVEL=WARNING cargo runExample output:
[2026-05-30 - 09:30:42:10] - WARNING - My Message here
LOG_LEVEL=DEBUG prints DEBUG, INFO, WARNING, ERROR
LOG_LEVEL=INFO prints INFO, WARNING, ERROR
LOG_LEVEL=WARNING prints WARNING, ERROR
LOG_LEVEL=WARN prints WARNING, ERROR
LOG_LEVEL=ERROR prints ERROR only
LOG_LEVEL=OFF prints nothing
Example if LOG_LEVEL is missing or invalid:
mini-log: LOG_LEVEL is not set, no logs will be printed.
Set one of these environment variable:
LOG_LEVEL=DEBUG
LOG_LEVEL=INFO
LOG_LEVEL=WARNING
LOG_LEVEL=ERROR
LOG_LEVEL=OFF
Powershell:
$env:LOG_LEVEL="WARNING"
cargo runcmd.exe
set LOG_LEVEL=WARNING
cargo runLOG_LEVEL=WARNING cargo runOnly this will be printed:
[2026-05-30 - 09:30:42:10] - WARNING - Warning message
[2026-05-30 - 09:30:42:10] - ERROR - Error message
By default, mini-log uses 24h timestamp format:
2026-05-30 - 09:30:42:10 (YYYY-MM-dd - hour:minute:second:millisecond)
The full log output looks like this:
[2026-05-30 - 09:30:42:10] - WARNING - My Message here
The timestamp format can be changed with the LOG_TIME_FORMAT environment variable.
Supported values:
LOG_TIME_FORMAT=DEFAULT 2026-05-30 - 09:30:42:10
LOG_TIME_FORMAT=RFC3339 2026-05-30T09:30:42.100+02:00
LOG_TIME_FORMAT=TIME_ONLY 09:30:42
LOG_TIME_FORMAT=DATE_ONLY 2026-05-30
LOG_TIME_FORMAT=UNIX 1780126242
Example:
LOG_LEVEL=WARNING LOG_TIME_FORMAT=RFC3339 cargo runExample output:
[2026-05-30T09:30:42.100+02:00] - WARNING - My Message here
If LOG_TIME_FORMAT is missing or invalid, mini-log uses the default timestamp format.
use mini_log::*;
fn main() {
LogMessage::new(Level::Debug, "Debug message");
LogMessage::new(Level::Info, "Info message");
LogMessage::new(Level::Warning, "Warning message");
LogMessage::new(Level::Error, "Error message");
}use mini_log::*;
fn main() {
if is_enabled(Level::Debug) {
println!("Debug logging is currently enabled");
}
LogMessage::new(Level::Warning, "My Message here");
}mini-log writes to stdout using println!.
It is intentionally small and simple.