]> Untitled Git - lemmy.git/commitdiff
Add feature for enabling json logging (#3462)
authorLemmus.org <137361180+lemmus-org@users.noreply.github.com>
Tue, 4 Jul 2023 11:11:47 +0000 (04:11 -0700)
committerGitHub <noreply@github.com>
Tue, 4 Jul 2023 11:11:47 +0000 (07:11 -0400)
Cargo.toml
src/lib.rs

index f73b6b531ffa1079f9edd6c53a6532b2fcd43ae4..311f5d7df449d407f2a77d53b39a1af53cb231e3 100644 (file)
@@ -27,6 +27,7 @@ lto = "thin"
 [features]
 embed-pictrs = ["pict-rs"]
 console = ["console-subscriber", "opentelemetry", "opentelemetry-otlp", "tracing-opentelemetry", "reqwest-tracing/opentelemetry_0_16"]
+json-log = ["tracing-subscriber/json"]
 default = []
 
 [workspace]
index cc77ca48f4ae395357639603f19b1a97dce5eeb1..f84842fe07ad4220e7265067e308e6a147915778 100644 (file)
@@ -185,7 +185,14 @@ pub fn init_logging(opentelemetry_url: &Option<Url>) -> Result<(), LemmyError> {
     .trim_matches('"')
     .parse::<Targets>()?;
 
-  let format_layer = tracing_subscriber::fmt::layer().with_filter(targets.clone());
+  let format_layer = {
+    #[cfg(feature = "json-log")]
+    let layer = tracing_subscriber::fmt::layer().json();
+    #[cfg(not(feature = "json-log"))]
+    let layer = tracing_subscriber::fmt::layer();
+
+    layer.with_filter(targets.clone())
+  };
 
   let subscriber = Registry::default()
     .with(format_layer)