6 releases (1 stable)
| new 1.0.0 | Feb 11, 2026 |
|---|---|
| 0.1.4 | Oct 13, 2025 |
| 0.1.3 | Dec 20, 2024 |
| 0.1.2 | Jul 25, 2024 |
| 0.1.0 | Jan 19, 2024 |
#196 in Debugging
8,592,763 downloads per month
Used in 6,423 crates
(22 directly)
48KB
975 lines
Filtering for log records.
You can use the Filter type in your own logger implementation to use the same
filter parsing and matching as env_logger.
Using env_filter in your own logger
You can use env_filter's filtering functionality with your own logger.
Call Builder::parse to parse directives from a string when constructing
your logger. Call Filter::matches to check whether a record should be
logged based on the parsed filters when log records are received.
use env_filter::Filter;
use log::{Log, Metadata, Record};
struct PrintLogger;
impl Log for PrintLogger {
fn enabled(&self, metadata: &Metadata) -> bool {
true
}
fn log(&self, record: &Record) {
println!("{:?}", record);
}
fn flush(&self) {}
}
let mut builder = env_filter::Builder::new();
// Parse a directives string from an environment variable
if let Ok(ref filter) = std::env::var("MY_LOG_LEVEL") {
builder.parse(filter);
}
let logger = env_filter::FilteredLog::new(PrintLogger, builder.build());
env_filter
Filter log events using environment variables
Dependencies
~2.5–4MB
~65K SLoC