Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optionally use JSON format for logs #2584

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sentry-tower = { version = "0.34.0", features = ["http"] }
sentry-anyhow = { version = "0.34.0", features = ["backtrace"] }
log = "0.4"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.16", default-features = false, features = ["ansi", "fmt", "env-filter", "tracing-log"] }
tracing-subscriber = { version = "0.3.16", default-features = false, features = ["ansi", "fmt", "json", "env-filter", "tracing-log"] }
tracing-log = "0.2.0"
regex = "1"
clap = { version = "4.0.22", features = [ "derive" ] }
Expand Down
24 changes: 16 additions & 8 deletions src/bin/cratesfyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@ fn main() {
// through rustwide.
rustwide::logging::init_with(LogTracer::new());

let tracing_registry = tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.with(
EnvFilter::builder()
.with_default_directive(Directive::from_str("docs_rs=info").unwrap())
.with_env_var("DOCSRS_LOG")
.from_env_lossy(),
);
let log_formatter = {
let log_format = env::var("DOCSRS_LOG_FORMAT").unwrap_or_default();

if log_format == "json" {
tracing_subscriber::fmt::layer().json().boxed()
} else {
tracing_subscriber::fmt::layer().boxed()
}
};

let tracing_registry = tracing_subscriber::registry().with(log_formatter).with(
EnvFilter::builder()
.with_default_directive(Directive::from_str("docs_rs=info").unwrap())
.with_env_var("DOCSRS_LOG")
.from_env_lossy(),
);

let _sentry_guard = if let Ok(sentry_dsn) = env::var("SENTRY_DSN") {
tracing::subscriber::set_global_default(tracing_registry.with(
Expand Down
Loading