2022-12-09 10:31:47 -05:00
|
|
|
pub mod api_routes_http;
|
|
|
|
pub mod api_routes_websocket;
|
2020-07-10 14:15:41 -04:00
|
|
|
pub mod code_migrations;
|
2021-12-06 09:54:47 -05:00
|
|
|
pub mod root_span_builder;
|
2021-01-29 11:38:27 -05:00
|
|
|
pub mod scheduled_tasks;
|
2022-02-04 12:31:38 -05:00
|
|
|
#[cfg(feature = "console")]
|
2022-05-10 08:06:32 -04:00
|
|
|
pub mod telemetry;
|
|
|
|
|
2022-06-02 10:33:41 -04:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2021-11-23 07:16:47 -05:00
|
|
|
use tracing::subscriber::set_global_default;
|
|
|
|
use tracing_error::ErrorLayer;
|
|
|
|
use tracing_log::LogTracer;
|
2022-01-07 09:53:45 -05:00
|
|
|
use tracing_subscriber::{filter::Targets, layer::SubscriberExt, Layer, Registry};
|
2022-07-11 16:38:37 -04:00
|
|
|
use url::Url;
|
2021-11-23 07:16:47 -05:00
|
|
|
|
2022-07-11 16:38:37 -04:00
|
|
|
pub fn init_logging(opentelemetry_url: &Option<Url>) -> Result<(), LemmyError> {
|
2021-11-23 07:16:47 -05:00
|
|
|
LogTracer::init()?;
|
|
|
|
|
2022-01-07 09:53:45 -05:00
|
|
|
let log_description = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into());
|
|
|
|
|
|
|
|
let targets = log_description
|
|
|
|
.trim()
|
|
|
|
.trim_matches('"')
|
|
|
|
.parse::<Targets>()?;
|
|
|
|
|
|
|
|
let format_layer = tracing_subscriber::fmt::layer().with_filter(targets.clone());
|
|
|
|
|
2021-11-23 07:16:47 -05:00
|
|
|
let subscriber = Registry::default()
|
|
|
|
.with(format_layer)
|
2022-02-04 12:31:38 -05:00
|
|
|
.with(ErrorLayer::default());
|
|
|
|
|
2022-05-10 08:06:32 -04:00
|
|
|
if let Some(_url) = opentelemetry_url {
|
|
|
|
#[cfg(feature = "console")]
|
2022-07-11 16:38:37 -04:00
|
|
|
telemetry::init_tracing(_url.as_ref(), subscriber, targets)?;
|
2022-05-10 08:06:32 -04:00
|
|
|
#[cfg(not(feature = "console"))]
|
|
|
|
tracing::error!("Feature `console` must be enabled for opentelemetry tracing");
|
2022-01-06 14:10:20 -05:00
|
|
|
} else {
|
|
|
|
set_global_default(subscriber)?;
|
|
|
|
}
|
2021-11-23 07:16:47 -05:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|