[][src]Struct tracing_subscriber::filter::EnvFilter

pub struct EnvFilter { /* fields omitted */ }
This is supported on feature="env-filter" only.

A Layer which filters spans and events based on a set of filter directives.

Directives

A filter consists of one or more directives which match on Spans and Events. Each directive may have a corresponding maximum verbosity level which enables (e.g., selects for) spans and events that match. Like log, tracing considers less exclusive levels (like trace or info) to be more verbose than more exclusive levels (like error or warn).

The directive syntax is similar to that of env_logger's. At a high level, the syntax for directives consists of several parts:

target[span{field=value}]=level

Each component (target, span, field, value, and level) will be covered in turn.

  • target matches the event or span's target. In general, this is the module path and/or crate name. Examples of targets h2, tokio::net, or tide::server. For more information on targets, please refer to Metadata's documentation.
  • span matches on the span's name. If a span directive is provided alongside a target, the span directive will match on spans within the target.
  • field matches on fields within spans. Field names can also be supplied without a value and will match on any Span or Event that has a field with that name. For example: [span{field=\"value\"}]=debug, [{field}]=trace.
  • value matches on the value of a span's field. If a value is a numeric literal or a bool, it will match only on that value. Otherwise, this filter acts as a regex on the std::fmt::Debug output from the value.
  • level sets a maximum verbosity level accepted by this directive.

Usage Notes

  • The portion of the directive which is included within the square brackets is tracing-specific.
  • Any portion of the directive can be omitted.
    • The sole exception are the field and value directives. If a value is provided, a field must also be provided. However, the converse does not hold, as fields can be matched without a value.
  • If only a level is provided, it will set the maximum level for all Spans and Events that are not enabled by other filters.
  • A directive without a level will enable anything that it matches. This is equivalent to =trace.

Examples

  • tokio::net=info will enable all spans or events that:
    • have the tokio::net target,
    • at the level info or above.
  • my_crate[span_a]=trace will enable all spans and events that:
    • are within the span_a span or named span_a if span_a has the target my_crate,
    • at the level trace or above.
  • [span_b{name=\"bob\"}] will enable all spans or event that:
    • have any target,
    • are inside a span named span_b,
    • which has a field named name with value bob,
    • at any level.

Implementations

impl EnvFilter[src]

pub const DEFAULT_ENV: &'static str[src]

RUST_LOG is the default environment variable used by EnvFilter::from_default_env and EnvFilter::try_from_default_env.

pub fn from_default_env() -> Self[src]

Returns a new EnvFilter from the value of the RUST_LOG environment variable, ignoring any invalid filter directives.

pub fn from_env<A: AsRef<str>>(env: A) -> Self[src]

Returns a new EnvFilter from the value of the given environment variable, ignoring any invalid filter directives.

pub fn new<S: AsRef<str>>(dirs: S) -> Self[src]

Returns a new EnvFilter from the directives in the given string, ignoring any that are invalid.

pub fn try_new<S: AsRef<str>>(dirs: S) -> Result<Self, ParseError>[src]

Returns a new EnvFilter from the directives in the given string, or an error if any are invalid.

pub fn try_from_default_env() -> Result<Self, FromEnvError>[src]

Returns a new EnvFilter from the value of the RUST_LOG environment variable, or an error if the environment variable contains any invalid filter directives.

pub fn try_from_env<A: AsRef<str>>(env: A) -> Result<Self, FromEnvError>[src]

Returns a new EnvFilter from the value of the given environment variable, or an error if the environment variable is unset or contains any invalid filter directives.

pub fn add_directive(self, directive: Directive) -> Self[src]

Add a filtering directive to this EnvFilter.

The added directive will be used in addition to any previously set directives, either added using this method or provided when the filter is constructed.

Filters may be created from may be LevelFilters, which will enable all traces at or below a certain verbosity level, or parsed from a string specifying a directive.

If a filter directive is inserted that matches exactly the same spans and events as a previous filter, but sets a different level for those spans and events, the previous directive is overwritten.

Examples

use tracing_subscriber::filter::{EnvFilter, LevelFilter};
let mut filter = EnvFilter::from_default_env()
    .add_directive(LevelFilter::INFO.into());
use tracing_subscriber::filter::{EnvFilter, Directive};

let mut filter = EnvFilter::try_from_default_env()?
    .add_directive("my_crate::module=trace".parse()?)
    .add_directive("my_crate::my_other_module::something=info".parse()?);

Trait Implementations

impl Debug for EnvFilter[src]

impl Default for EnvFilter[src]

impl Display for EnvFilter[src]

impl<S> From<S> for EnvFilter where
    S: AsRef<str>, 
[src]

impl FromStr for EnvFilter[src]

type Err = ParseError

The associated error which can be returned from parsing.

impl<S: Subscriber> Layer<S> for EnvFilter[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.