1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! This module provides utilities for setting up application-wide logging and tracing.
//!
//! It leverages the `tracing` and `tracing-subscriber` crates to configure
//! how log events and spans are collected and emitted, allowing for better
//! observability of the Molten API.
use Subscriber;
use set_global_default;
use LogTracer;
use MakeWriter;
use ;
/// 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.
+ Send + Sync
where
// Function is generic for MakeWriter trait allowing us to choose
// where messages are written to (e.g., std::io::{stdout, sink} )
Sink: for<'a> + Send + Sync + 'static,
/// Initializes the global default tracing subscriber.
///
/// This function sets the provided `subscriber` as the global default for processing
/// `tracing` spans and events. It also redirects `log` crate events to this subscriber.
///
/// # Arguments
/// * `subscriber` - An `impl Subscriber + Send + Sync` which will be set as the global default.
///
/// # Panics
/// Panics if unable to set the global logger or subscriber, typically indicating
/// that a subscriber has already been set.