A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html below:

EnvFilter in tracing_subscriber::filter - Rust

pub struct EnvFilter {  }

Available on crate features env-filter and std only.

Expand description

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

EnvFilter implements both the Layer and Filter traits, so it may be used for both global filtering and per-layer filtering, respectively. See the documentation on filtering with Layers for details.

The Targets type implements a similar form of filtering, but without the ability to dynamically enable events based on the current span context, and without filtering on field values. When these features are not required, Targets provides a lighter-weight alternative to EnvFilter.

§Directives

A filter consists of one or more comma-separated 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.

When a field value directive ([{<FIELD NAME>=<FIELD_VALUE>}]=...) matches a value’s std::fmt::Debug output (i.e., the field value in the directive is not a bool, i64, u64, or f64 literal), the matched pattern may be interpreted as either a regular expression or as the precise expected output of the field’s std::fmt::Debug implementation. By default, these filters are interpreted as regular expressions, but this can be disabled using the Builder::with_regex builder method to use precise matching instead.

When field value filters are interpreted as regular expressions, the [regex-automata crate’s regular expression syntax][re-syntax] is supported.

Note: When filters are constructed from potentially untrusted inputs, disabling regular expression matching is strongly recommended.

§Usage Notes §Example Syntax §Examples

Parsing an EnvFilter from the default environment variable (RUST_LOG):

use tracing_subscriber::{EnvFilter, fmt, prelude::*};

tracing_subscriber::registry()
    .with(fmt::layer())
    .with(EnvFilter::from_default_env())
    .init();

Parsing an EnvFilter from a user-provided environment variable:

use tracing_subscriber::{EnvFilter, fmt, prelude::*};

tracing_subscriber::registry()
    .with(fmt::layer())
    .with(EnvFilter::from_env("MYAPP_LOG"))
    .init();

Using EnvFilter as a per-layer filter to filter only a single Layer:

use tracing_subscriber::{EnvFilter, fmt, prelude::*};

let filter = EnvFilter::from_default_env();

let filtered_layer = fmt::layer().with_filter(filter);

let unfiltered_layer = tracing_subscriber::registry()
    .with(filtered_layer)
    .with(unfiltered_layer)
    .init();
§Constructing EnvFilters

An EnvFilter is be constructed by parsing a string containing one or more directives. The EnvFilter::new constructor parses an EnvFilter from a string, ignoring any invalid directives, while EnvFilter::try_new returns an error if invalid directives are encountered. Similarly, the EnvFilter::from_env and EnvFilter::try_from_env constructors parse an EnvFilter from the value of the provided environment variable, with lossy and strict validation, respectively.

A builder interface is available to set additional configuration options prior to parsing an EnvFilter. See the Builder type’s documentation for details on the options that can be configured using the builder.

Source§ Source

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

Source Source

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

If the environment variable is empty or not set, or if it contains only invalid directives, a default directive enabling the ERROR level is added.

To set additional configuration options prior to parsing the filter, use the Builder type instead.

This function is equivalent to the following:

use tracing_subscriber::filter::{EnvFilter, LevelFilter};

EnvFilter::builder()
    .with_default_directive(LevelFilter::ERROR.into())
    .from_env_lossy()
Source

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

If the environment variable is empty or not set, or if it contains only invalid directives, a default directive enabling the ERROR level is added.

To set additional configuration options prior to parsing the filter, use the Builder type instead.

This function is equivalent to the following:

use tracing_subscriber::filter::{EnvFilter, LevelFilter};

EnvFilter::builder()
    .with_default_directive(LevelFilter::ERROR.into())
    .with_env_var(env)
    .from_env_lossy()
Source

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

If the string is empty or contains only invalid directives, a default directive enabling the ERROR level is added.

To set additional configuration options prior to parsing the filter, use the Builder type instead.

This function is equivalent to the following:

use tracing_subscriber::filter::{EnvFilter, LevelFilter};

EnvFilter::builder()
    .with_default_directive(LevelFilter::ERROR.into())
    .parse_lossy(directives)
Source

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

If the string is empty, a default directive enabling the ERROR level is added.

To set additional configuration options prior to parsing the filter, use the Builder type instead.

This function is equivalent to the following:

use tracing_subscriber::filter::{EnvFilter, LevelFilter};

EnvFilter::builder()
    .with_default_directive(LevelFilter::ERROR.into())
    .parse(directives)
Source

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

To set additional configuration options prior to parsing the filter, use the Builder type instead.

This function is equivalent to the following:

use tracing_subscriber::EnvFilter;

EnvFilter::builder().try_from_env()
Source

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.

To set additional configuration options prior to parsing the filter, use the Builder type instead.

This function is equivalent to the following:

use tracing_subscriber::EnvFilter;

EnvFilter::builder().with_env_var(env).try_from_env()
Source

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 LevelFilter or Level, 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

From LevelFilter:

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

Or from Level:

let mut filter = EnvFilter::from_default_env()
    .add_directive(Level::INFO.into());

Parsed from a string:

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

In the above example, substitute my_crate, module, etc. with the name your target crate/module is imported with. This might be different from the package name in Cargo.toml (- is replaced by _). Example, if the package name in your Cargo.toml is MY-FANCY-LIB, then the corresponding Rust identifier would be MY_FANCY_LIB:

Source

Returns true if this EnvFilter would enable the provided metadata in the current context.

This is equivalent to calling the Layer::enabled or Filter::enabled methods on EnvFilter’s implementations of those traits, but it does not require the trait to be in scope.

Source Source

Informs the filter that a new span was created.

This is equivalent to calling the Layer::on_new_span or Filter::on_new_span methods on EnvFilter’s implementations of those traits, but it does not require the trait to be in scope.

Source

Informs the filter that the span with the provided id was entered.

This is equivalent to calling the Layer::on_enter or Filter::on_enter methods on EnvFilter’s implementations of those traits, but it does not require the trait to be in scope.

Source

Informs the filter that the span with the provided id was exited.

This is equivalent to calling the Layer::on_exit or Filter::on_exit methods on EnvFilter’s implementations of those traits, but it does not require the trait to be in scope.

Source

Informs the filter that the span with the provided id was closed.

This is equivalent to calling the Layer::on_close or Filter::on_close methods on EnvFilter’s implementations of those traits, but it does not require the trait to be in scope.

Source

Informs the filter that the span with the provided id recorded the provided field values.

This is equivalent to calling the Layer::on_record or Filter::on_record methods on EnvFilter’s implementations of those traits, but it does not require the trait to be in scope

Source§ Source§ Source§ Source§

Available on crate feature registry only.

Source§ Source§ Source§ Source§

Notifies this filter that a new span was constructed with the given

Attributes

and

Id

.

Read more Source§

Notifies this filter that a span with the given

Id

recorded the given

values

.

Read more Source§

Notifies this filter that a span with the given ID was entered.

Read more Source§

Notifies this filter that a span with the given ID was exited.

Read more Source§

Notifies this filter that a span with the given ID has been closed.

Read more Source§

Called before the filtered [

Layer]'s [

on_event

], to determine if

on_event` should be called.

Read more Source§ Source§

Converts to this type from the input type.

Source§ Source§

The associated error which can be returned from parsing.

Source§

Parses a string

s

to return a value of this type.

Read more Source§ Source§ Source§ Source§

Notifies this layer that a new span was constructed with the given Attributes and Id.

Source§

Notifies this layer that a span with the given Id recorded the given values.

Source§

Notifies this layer that a span with the given ID was entered.

Source§

Notifies this layer that the span with the given ID was exited.

Source§

Notifies this layer that the span with the given ID has been closed.

Source§ Source§ Source§

Notifies this layer that a span with the ID span recorded that it follows from the span with the ID follows.

Source§ Source§

Notifies this layer that an event has occurred.

Source§

Notifies this layer that a span ID has been cloned, and that the subscriber returned a different ID.

Source§

Composes this layer around the given

Layer

, returning a

Layered

struct implementing

Layer

.

Read more Source§ Source§

Available on crate feature registry only.

Source§

Available on crate features alloc or std only.

Source§ Source§ Source§ Source§ Source§

Available on crate features registry and std only.

Combines this

Filter

with another

Filter

s so that spans and events are enabled if and only if

both

filters return

true

.

Read more Source§

Available on crate features registry and std only.

Combines two

Filter

s so that spans and events are enabled if

either

filter returns

true

.

Read more Source§

Available on crate features registry and std only.

Inverts

self

, returning a filter that enables spans and events only if

self

would

not

enable them.

Read more Source§

Available on crate features registry and std only.

Source§ Source§

Returns the argument unchanged.

Source§ Source§ Source§

Calls U::from(self).

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

Source§ Source§ Source§

The type returned in the event of a conversion error.

Source§

Performs the conversion.

Source§ Source§

The type returned in the event of a conversion error.

Source§

Performs the conversion.

Source§

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4