TiSubscriberExt

Trait TiSubscriberExt 

Source
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§

Source

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

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>,

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 Layered type: a new Subscriber composed of the original subscriber and the added fmt::Layer.
§Details
  • Uses fmt::Layer to log events to a file instead of stdout/stderr.
  • ANSI color output is disabled (with_ansi(false)).
  • The file is opened in append mode, so new logs are added to the end.
  • A new file handle is opened each time logs are written (based on MakeWriter behavior).
§Example
use ts_init::prelude::*;

ts_init::subscriber()
    .with_file("app.log")
    .init();
Source

fn with_journald(self) -> Layered<Layer, Self>
where for<'span> Self: Sized + LookupSpan<'span>,

Implementors§