support_kit/logs/
logging.rs1use tracing_appender::non_blocking::WorkerGuard;
2
3use crate::{Configuration, TracingTargets};
4
5use super::LoggingConfig;
6
7#[derive(Default)]
8pub struct Logging {
9 config: LoggingConfig,
10 pub loggers: TracingTargets,
11 pub guards: Vec<WorkerGuard>,
12}
13
14impl Logging {
15 pub fn initialize(config: Configuration) -> Vec<WorkerGuard> {
16 use tracing_subscriber::layer::SubscriberExt;
17
18 let mut logging = Self::default();
19
20 for logger in config.loggers() {
21 logger.initialize(&config, &mut logging)
22 }
23
24 let subscriber = tracing_subscriber::registry().with(logging.loggers);
25
26 tracing::subscriber::set_global_default(subscriber)
27 .expect("Unable to set a global subscriber");
28
29 logging.guards
30 }
31}
32
33impl std::fmt::Debug for Logging {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 f.debug_struct("Logging")
36 .field("config", &self.config)
37 .field("loggers", &self.loggers.len())
38 .field("guards", &self.guards)
39 .finish()
40 }
41}
42
43impl PartialEq for Logging {
44 fn eq(&self, other: &Self) -> bool {
45 self.config == other.config
46 }
47}