Expand description
Filtering for log records.
You can use theFilter
type in your own logger implementation to use the samefilter parsing and matching asenv_logger
.
§Usingenv_filter
in your own logger
You can useenv_filter
’s filtering functionality with your own logger.CallBuilder::parse
to parse directives from a string when constructingyour logger. CallFilter::matches
to check whether a record should belogged based on the parsed filters when log records are received.
useenv_filter::Filter;uselog::{Log, Metadata, Record};structPrintLogger;implLogforPrintLogger {fnenabled(&self, metadata:&Metadata) -> bool {true}fnlog(&self, record:&Record) {println!("{:?}", record); }fnflush(&self) {}}letmutbuilder = env_filter::Builder::new();// Parse a directives string from an environment variableif letOk(reffilter) = std::env::var("MY_LOG_LEVEL") { builder.parse(filter);}letlogger = env_filter::FilteredLog::new(PrintLogger, builder.build());
Structs§
- Builder
- A builder for a log filter.
- Filter
- A log filter.
- Filtered
Log - Decorate a
log::Log
with recordFilter
ing. - Parse
Error - Error during logger directive parsing process.