Skip to content

Commit

Permalink
Add feature for enabling json logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmus-org authored and Nutomic committed Jul 3, 2023
1 parent 050216e commit edf1e9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit edf1e9e

Please sign in to comment.