1 #![recursion_limit = "512"]
3 pub mod code_migrations;
4 pub mod root_span_builder;
5 pub mod scheduled_tasks;
6 #[cfg(feature = "console")]
9 use lemmy_utils::error::LemmyError;
10 use tracing::subscriber::set_global_default;
11 use tracing_error::ErrorLayer;
12 use tracing_log::LogTracer;
13 use tracing_subscriber::{filter::Targets, layer::SubscriberExt, Layer, Registry};
16 pub fn init_logging(opentelemetry_url: &Option<Url>) -> Result<(), LemmyError> {
19 let log_description = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into());
21 let targets = log_description
26 let format_layer = tracing_subscriber::fmt::layer().with_filter(targets.clone());
28 let subscriber = Registry::default()
30 .with(ErrorLayer::default());
32 if let Some(_url) = opentelemetry_url {
33 #[cfg(feature = "console")]
34 telemetry::init_tracing(_url.as_ref(), subscriber, targets)?;
35 #[cfg(not(feature = "console"))]
36 tracing::error!("Feature `console` must be enabled for opentelemetry tracing");
38 set_global_default(subscriber)?;