WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit bdb80ba

Browse files
Configure tracing error layer for non wasm targets
1 parent 50c168c commit bdb80ba

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ tokio = { workspace = true, features = ["signal"] }
7777
tokio-util = "0.7.10"
7878
tracing = { workspace = true }
7979
tracing-subscriber = { workspace = true }
80+
tracing-error = "0.2"
8081
uuid = { workspace = true }
8182
void = { workspace = true }
8283
warp = { workspace = true }

core/src/utils.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ use tokio::task::JoinHandle;
2424
#[cfg(target_arch = "wasm32")]
2525
use tokio_with_wasm::alias as tokio;
2626
use tracing::{error, warn, Instrument, Level, Subscriber};
27+
#[cfg(not(target_arch = "wasm32"))]
28+
use tracing_error::ErrorLayer;
29+
#[cfg(not(target_arch = "wasm32"))]
30+
use tracing_subscriber::layer::SubscriberExt;
2731
use tracing_subscriber::{fmt::format, EnvFilter, FmtSubscriber};
2832

2933
#[cfg(feature = "multiproof")]
@@ -194,18 +198,36 @@ pub fn install_panic_hooks(shutdown: Controller<String>) -> Result<()> {
194198
}
195199

196200
pub fn json_subscriber(log_level: Level) -> impl Subscriber + Send + Sync {
197-
FmtSubscriber::builder()
201+
let subscriber = FmtSubscriber::builder()
198202
.json()
199203
.with_env_filter(EnvFilter::new(format!("avail_light={log_level}")))
200204
.with_span_events(format::FmtSpan::CLOSE)
201-
.finish()
205+
.finish();
206+
207+
#[cfg(not(target_arch = "wasm32"))]
208+
{
209+
subscriber.with(ErrorLayer::default())
210+
}
211+
#[cfg(target_arch = "wasm32")]
212+
{
213+
subscriber
214+
}
202215
}
203216

204217
pub fn default_subscriber(log_level: Level) -> impl Subscriber + Send + Sync {
205-
FmtSubscriber::builder()
218+
let subscriber = FmtSubscriber::builder()
206219
.with_env_filter(EnvFilter::new(format!("avail_light={log_level}")))
207220
.with_span_events(format::FmtSpan::CLOSE)
208-
.finish()
221+
.finish();
222+
223+
#[cfg(not(target_arch = "wasm32"))]
224+
{
225+
subscriber.with(ErrorLayer::default())
226+
}
227+
#[cfg(target_arch = "wasm32")]
228+
{
229+
subscriber
230+
}
209231
}
210232

211233
#[cfg(target_arch = "wasm32")]

0 commit comments

Comments
 (0)