Skip to main content

RustLogFilterBuilder

Struct RustLogFilterBuilder 

Source
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

Source

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();
Source

pub fn from_default_env_or<'a, V>(default: V) -> Self
where V: Into<Cow<'a, str>>,

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();
Source

pub fn from_env<'a, V>(name: V) -> RustLogFilterBuilder
where V: Into<Cow<'a, str>>,

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();
Source

pub fn from_env_or<'a, 'b, E, V>(name: E, default: V) -> Self
where E: Into<Cow<'a, str>>, V: Into<Cow<'b, str>>,

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();
Source

pub fn from_spec<'a, V>(spec: V) -> Self
where V: Into<Cow<'a, str>>,

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();
Source

pub fn try_from_spec<'a, V>(spec: V) -> Result<Self, Error>
where V: Into<Cow<'a, str>>,

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();
Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for RustLogFilterBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RustLogFilterBuilder

Source§

fn default() -> RustLogFilterBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.