Skip to main content

get_subscriber

Function get_subscriber 

Source
pub fn get_subscriber<Sink>(
    env_filter: String,
    sink: Sink,
) -> impl Subscriber + Send + Sync
where Sink: for<'a> MakeWriter<'a> + Send + Sync + 'static,
Expand description

Returns a Subscriber that can be used for logging and tracing.

This function configures an EnvFilter to filter log events based on environment variables or a default filter string, and sets up a fmt layer for formatting and outputting log records to a specified sink.

§Arguments

  • env_filter - A string defining the default logging level and filter directives.
  • sink - A type that implements MakeWriter trait, determining where the logs are written (e.g., stdout, stderr, a file).

§Type Parameters

  • Sink - A type that can create std::io::Write instances, enabling flexible log output.

§Returns

An impl Subscriber + Send + Sync configured with the specified filter and sink.