pub trait TiSubscriberExt: Subscriber {
// Provided methods
fn with_env_filter_or<S: AsRef<str>>(
self,
default_env: S,
) -> Layered<EnvFilter, Self>
where Self: Sized { ... }
fn with_file<P>(
self,
path: P,
) -> Layered<Layer<Self, DefaultFields, Format<Full>, FileMakeWriter>, Self>
where for<'span> Self: Sized + LookupSpan<'span>,
P: AsRef<Path> { ... }
fn with_journald(self) -> Layered<Layer, Self>
where for<'span> Self: Sized + LookupSpan<'span> { ... }
}Provided Methods§
Sourcefn with_env_filter_or<S: AsRef<str>>(
self,
default_env: S,
) -> Layered<EnvFilter, Self>where
Self: Sized,
fn with_env_filter_or<S: AsRef<str>>(
self,
default_env: S,
) -> Layered<EnvFilter, Self>where
Self: Sized,
Adds an EnvFilter layer to this subscriber.
This first attempts to read the filter from the RUST_LOG environment
variable. If that fails, it falls back to the provided directive string s.
§Arguments
default_env– a default directive string, e.g."info,my_crate=debug".
§Example
use ts_init::prelude::*;
let subscriber = ts_init::subscriber()
.with_env_filter_or("info,my_crate=debug")
.init();Sourcefn with_file<P>(
self,
path: P,
) -> Layered<Layer<Self, DefaultFields, Format<Full>, FileMakeWriter>, Self>
fn with_file<P>( self, path: P, ) -> Layered<Layer<Self, DefaultFields, Format<Full>, FileMakeWriter>, Self>
Adds a fmt::Layer to the Subscriber that writes logs to a specified file path.
§Arguments
path: The path to the log file where logs will be written.
§Returns
- A
Layeredtype: a newSubscribercomposed of the original subscriber and the addedfmt::Layer.
§Details
- Uses
fmt::Layerto log events to a file instead of stdout/stderr. - ANSI color output is disabled (
with_ansi(false)). - The file is opened in
appendmode, so new logs are added to the end. - A new file handle is opened each time logs are written (based on
MakeWriterbehavior).
§Example
use ts_init::prelude::*;
ts_init::subscriber()
.with_file("app.log")
.init();