From ff47d97bd34d303dc8dd687bca29f5d9755a59af Mon Sep 17 00:00:00 2001 From: "Lemmus.org" <137361180+lemmus-org@users.noreply.github.com> Date: Tue, 4 Jul 2023 04:11:47 -0700 Subject: [PATCH] Add feature for enabling json logging (#3462) --- Cargo.toml | 1 + src/lib.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f73b6b53..311f5d7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/src/lib.rs b/src/lib.rs index cc77ca48..f84842fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,7 +185,14 @@ pub fn init_logging(opentelemetry_url: &Option) -> Result<(), LemmyError> { .trim_matches('"') .parse::()?; - 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) -- 2.44.1