pub struct RustLogFilterBuilder { /* private fields */ }Expand description
A builder for RustLogFilter.
It can be used to parse a set of directives from a string before building an RustLogFilter
instance.
§Example
use logforth_filter_rustlog::RustLogFilterBuilder;
// Parse the filter from the default environment variable `RUST_LOG`.
let builder = RustLogFilterBuilder::from_default_env();
let filter = builder.build();Implementations§
Source§impl RustLogFilterBuilder
impl RustLogFilterBuilder
Sourcepub fn from_default_env() -> Self
pub fn from_default_env() -> Self
Initialize the filter builder from the environment using default variable name RUST_LOG.
§Examples
Initialize a filter using the default environment variables:
use logforth_filter_rustlog::RustLogFilterBuilder;
let filter = RustLogFilterBuilder::from_default_env().build();Sourcepub fn from_default_env_or<'a, V>(default: V) -> Self
pub fn from_default_env_or<'a, V>(default: V) -> Self
Initialize the filter builder from the environment using default variable name RUST_LOG.
If the variable is not set, the default value will be used.
§Examples
Initialize a filter using the default environment variables, or fallback to the default value:
use logforth_filter_rustlog::RustLogFilterBuilder;
let filter = RustLogFilterBuilder::from_default_env_or("info").build();Sourcepub fn from_env<'a, V>(name: V) -> RustLogFilterBuilder
pub fn from_env<'a, V>(name: V) -> RustLogFilterBuilder
Initialize the filter builder from the environment using specific variable name.
§Examples
Initialize a filter using the using specific variable name:
use logforth_filter_rustlog::RustLogFilterBuilder;
let filter = RustLogFilterBuilder::from_env("MY_LOG").build();Sourcepub fn from_env_or<'a, 'b, E, V>(name: E, default: V) -> Self
pub fn from_env_or<'a, 'b, E, V>(name: E, default: V) -> Self
Initialize the filter builder from the environment using specific variable name. If the variable is not set, the default value will be used.
§Examples
Initialize a filter using the using specific variable name, or fallback to the default value:
use logforth_filter_rustlog::RustLogFilterBuilder;
let filter = RustLogFilterBuilder::from_env_or("MY_LOG", "info").build();Sourcepub fn from_spec<'a, V>(spec: V) -> Self
pub fn from_spec<'a, V>(spec: V) -> Self
Initialize the filter builder from the passed RUST_LOG specification. Malformed directives will be ignored with a warning printed to stderr.
§Examples
Initialize a filter using the passed RUST_LOG specification:
use logforth_filter_rustlog::RustLogFilterBuilder;
let filter = RustLogFilterBuilder::from_spec("info,my_crate=debug").build();Sourcepub fn try_from_spec<'a, V>(spec: V) -> Result<Self, Error>
pub fn try_from_spec<'a, V>(spec: V) -> Result<Self, Error>
Initialize the filter builder from the passed RUST_LOG specification.
§Examples
Initialize a filter using the passed RUST_LOG specification:
use logforth_filter_rustlog::RustLogFilterBuilder;
let filter = RustLogFilterBuilder::try_from_spec("info,my_crate=debug")
.unwrap()
.build();Sourcepub fn build(self) -> RustLogFilter
pub fn build(self) -> RustLogFilter
Consume the builder to produce an RustLogFilter.
If the builder has no directives configured, a default directive of the error level will
be added.
Sourcepub fn filter_module(
self,
module: impl Into<String>,
level: LevelFilter,
) -> Self
pub fn filter_module( self, module: impl Into<String>, level: LevelFilter, ) -> Self
Add a directive to the filter for a specific module.
The given module will log at most the specified level provided.
Sourcepub fn filter_level(self, level: LevelFilter) -> Self
pub fn filter_level(self, level: LevelFilter) -> Self
Add a directive to the filter for all modules.
All log messages will log at most the specified level provided.