Skip to content

Commit c936b1b

Browse files
committed
Set subscribers defaults instead of using once
Use `tracing::subscriber::set_default` for setting the subscriber on a thread/test. Using `std::sync::Once` would cause any subsequent tests that try to use a different level won't see their preferred level applied, and it would not be obvious why debug logs aren't showing.
1 parent 3c8a605 commit c936b1b

File tree

1 file changed

+3
-6
lines changed
  • beacon_node/lighthouse_network/tests

1 file changed

+3
-6
lines changed

beacon_node/lighthouse_network/tests/common.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ use types::{
1313
ChainSpec, EnrForkId, Epoch, EthSpec, FixedBytesExtended, ForkContext, ForkName, Hash256,
1414
MinimalEthSpec,
1515
};
16-
use std::sync::Once;
17-
18-
static INIT: Once = Once::new();
1916

2017
type E = MinimalEthSpec;
2118

@@ -77,11 +74,11 @@ impl std::ops::DerefMut for Libp2pInstance {
7774
#[allow(unused)]
7875
pub fn build_tracing_subscriber(level: &str, enabled: bool) {
7976
if enabled {
80-
INIT.call_once(|| {
77+
tracing::subscriber::set_default(
8178
tracing_subscriber::fmt()
8279
.with_env_filter(EnvFilter::try_new(level).unwrap())
83-
.init();
84-
});
80+
.finish()
81+
);
8582
}
8683
}
8784

0 commit comments

Comments
 (0)