mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-12 16:50:10 +00:00
chore(rust): clean up duplicated sentry code
This commit is contained in:
parent
3cf71112d6
commit
f2583904ef
1 changed files with 13 additions and 25 deletions
|
|
@ -16,44 +16,32 @@ pub use crate::_config::CONFIG as config;
|
||||||
// functions in this file are only used by the main function below
|
// functions in this file are only used by the main function below
|
||||||
|
|
||||||
pub fn init_logging(component: &str) {
|
pub fn init_logging(component: &str) {
|
||||||
// todo: clean up the sentry duplication
|
let sentry_layer =
|
||||||
if config.json_log {
|
sentry_tracing::layer().event_mapper(|md, ctx| match md.metadata().level() {
|
||||||
let sentry_layer =
|
&tracing::Level::ERROR => {
|
||||||
sentry_tracing::layer().event_mapper(|md, ctx| match md.metadata().level() {
|
// for some reason this works, but letting the library handle it doesn't
|
||||||
&tracing::Level::ERROR => {
|
let event = event_from_event(md, ctx);
|
||||||
// for some reason this works, but letting the library handle it doesn't
|
sentry::capture_event(event);
|
||||||
let event = event_from_event(md, ctx);
|
sentry_tracing::EventMapping::Ignore
|
||||||
sentry::capture_event(event);
|
}
|
||||||
sentry_tracing::EventMapping::Ignore
|
_ => sentry_tracing::EventMapping::Ignore,
|
||||||
}
|
});
|
||||||
_ => sentry_tracing::EventMapping::Ignore,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
if config.json_log {
|
||||||
let mut layer = json_subscriber::layer();
|
let mut layer = json_subscriber::layer();
|
||||||
layer.inner_layer_mut().add_static_field(
|
layer.inner_layer_mut().add_static_field(
|
||||||
"component",
|
"component",
|
||||||
serde_json::Value::String(component.to_string()),
|
serde_json::Value::String(component.to_string()),
|
||||||
);
|
);
|
||||||
tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(layer)
|
|
||||||
.with(sentry_layer)
|
.with(sentry_layer)
|
||||||
|
.with(layer)
|
||||||
.with(EnvFilter::from_default_env())
|
.with(EnvFilter::from_default_env())
|
||||||
.init();
|
.init();
|
||||||
} else {
|
} else {
|
||||||
let sentry_layer =
|
|
||||||
sentry_tracing::layer().event_mapper(|md, ctx| match md.metadata().level() {
|
|
||||||
&tracing::Level::ERROR => {
|
|
||||||
// for some reason this works, but letting the library handle it doesn't
|
|
||||||
let event = event_from_event(md, ctx);
|
|
||||||
sentry::capture_event(event);
|
|
||||||
sentry_tracing::EventMapping::Ignore
|
|
||||||
}
|
|
||||||
_ => sentry_tracing::EventMapping::Ignore,
|
|
||||||
});
|
|
||||||
|
|
||||||
tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(tracing_subscriber::fmt::layer())
|
|
||||||
.with(sentry_layer)
|
.with(sentry_layer)
|
||||||
|
.with(tracing_subscriber::fmt::layer())
|
||||||
.init();
|
.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue