Initialise the global tracing subscriber based on the config log format. Uses `RUST_LOG` env var for the filter if set; otherwise defaults to `warn` for a clean startup. Must be called after config is loaded and before any `tracing::info!` / `tracing::warn!` calls are expected to emit.
(config: &ServerConfig)
| 13 | /// for a clean startup. Must be called after config is loaded and before any |
| 14 | /// `tracing::info!` / `tracing::warn!` calls are expected to emit. |
| 15 | pub fn init_tracing(config: &ServerConfig) { |
| 16 | let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("warn")); |
| 17 | if config.server.log_format == crate::config::LogFormat::Json { |
| 18 | tracing_subscriber::registry() |
| 19 | .with( |
| 20 | tracing_subscriber::fmt::layer() |
| 21 | .with_writer(std::io::stderr) |
| 22 | .json() |
| 23 | .flatten_event(true) |
| 24 | .with_filter(filter), |
| 25 | ) |
| 26 | .init(); |
| 27 | } else { |
| 28 | tracing_subscriber::registry() |
| 29 | .with( |
| 30 | tracing_subscriber::fmt::layer() |
| 31 | .with_writer(std::io::stderr) |
| 32 | .with_filter(filter), |
| 33 | ) |
| 34 | .init(); |
| 35 | } |
| 36 | } |