Skip to content

Commit 4c1d262

Browse files
Nemo157syphar
authored andcommitted
Improve formatting of rustwide log messages
Enables `tracing-subscriber/tracing-log` feature to get its support for formatting based on these messages custom attributes. Requires manually registering the registry to avoid `tracing-subscriber` attempting to register its own `tracing-log` instance as we've already registered one through `rustwide`.
1 parent 831e906 commit 4c1d262

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ sentry-tower = { version = "0.31.0", features = ["http"] }
2727
sentry-anyhow = { version = "0.31.0", features = ["backtrace"] }
2828
log = "0.4"
2929
tracing = "0.1.37"
30-
tracing-subscriber = { version = "0.3.16", default-features = false, features = ["ansi", "fmt", "env-filter"] }
30+
tracing-subscriber = { version = "0.3.16", default-features = false, features = ["ansi", "fmt", "env-filter", "tracing-log"] }
3131
tracing-log = "0.2.0"
3232
regex = "1"
3333
clap = { version = "4.0.22", features = [ "derive" ] }

src/bin/cratesfyi.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ fn main() {
4141
);
4242

4343
let _sentry_guard = if let Ok(sentry_dsn) = env::var("SENTRY_DSN") {
44-
tracing_registry
45-
.with(sentry_tracing::layer().event_filter(|md| {
44+
tracing::subscriber::set_global_default(tracing_registry.with(
45+
sentry_tracing::layer().event_filter(|md| {
4646
if md.fields().field("reported_to_sentry").is_some() {
4747
sentry_tracing::EventFilter::Ignore
4848
} else {
4949
sentry_tracing::default_event_filter(md)
5050
}
51-
}))
52-
.init();
51+
}),
52+
))
53+
.unwrap();
5354

5455
Some(sentry::init((
5556
sentry_dsn,
@@ -65,7 +66,7 @@ fn main() {
6566
.add_integration(sentry_panic::PanicIntegration::default()),
6667
)))
6768
} else {
68-
tracing_registry.init();
69+
tracing::subscriber::set_global_default(tracing_registry).unwrap();
6970
None
7071
};
7172

0 commit comments

Comments
 (0)