Skip to content

Commit d3b6daf

Browse files
authored
Set up tracing subscriber on TestFramework init (#23)
* Set up tracing subscriber on TestFramework init * Discard tracing subscriber already set errors
1 parent e85ecd3 commit d3b6daf

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ bollard = { version = "0.17.1" }
1313
futures = "0.3"
1414
hex = { version = "0.4.3", default-features = false, features = ["serde"] }
1515
jsonrpsee = { version = "0.24.2", features = ["http-client", "ws-client"] }
16+
log-panics = { version = "2", features = ["with-backtrace"] }
1617
rand = "0.8"
1718
serde = { version = "1.0.192", default-features = false, features = ["alloc", "derive"] }
1819
serde_json = { version = "1.0", default-features = false }
1920
tempfile = "3.8"
2021
tokio = { version = "1.39", features = ["full"] }
2122
toml = "0.8.0"
2223
tracing = { version = "0.1.40", default-features = false }
24+
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json", "fmt"] }
2325

2426
# Citrea dependencies
2527
sov-ledger-rpc = { git = "https://github.com/chainwayxyz/citrea", rev = "82bf52d", default-features = false, features = ["client"] }

src/batch_prover.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time::SystemTime;
22

33
use anyhow::bail;
44
use tokio::time::{sleep, Duration};
5-
use tracing::debug;
5+
use tracing::trace;
66

77
use super::{config::FullBatchProverConfig, Result};
88
use crate::node::Node;
@@ -14,7 +14,7 @@ impl BatchProver {
1414
let start = SystemTime::now();
1515
let timeout = timeout.unwrap_or(Duration::from_secs(600));
1616
loop {
17-
debug!("Waiting for batch prover height {}", height);
17+
trace!("Waiting for batch prover height {}", height);
1818
let latest_block = self.client.ledger_get_last_scanned_l1_height().await?;
1919

2020
if latest_block >= height {

src/framework.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
use std::{future::Future, sync::Arc};
1+
use std::{
2+
future::Future,
3+
sync::{Arc, Once},
4+
};
25

36
use bitcoincore_rpc::RpcApi;
47
use tracing::{debug, info};
8+
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
59

610
use super::{
711
bitcoin::BitcoinNodeCluster, config::TestConfig, docker::DockerEnv, full_node::FullNode,
@@ -53,6 +57,8 @@ async fn create_optional<T>(pred: bool, f: impl Future<Output = Result<T>>) -> R
5357

5458
impl TestFramework {
5559
pub async fn new(config: TestConfig) -> Result<Self> {
60+
setup_logging();
61+
5662
anyhow::ensure!(
5763
config.test_case.n_nodes > 0,
5864
"At least one bitcoin node has to be running"
@@ -219,3 +225,27 @@ impl TestFramework {
219225
Ok(())
220226
}
221227
}
228+
229+
static INIT: Once = Once::new();
230+
231+
fn setup_logging() {
232+
INIT.call_once(|| {
233+
let env_filter = EnvFilter::try_from_default_env()
234+
.or_else(|_| EnvFilter::try_new("citrea_e2e=info"))
235+
.unwrap();
236+
237+
if std::env::var("JSON_LOGS").is_ok() {
238+
let _ = tracing_subscriber::registry()
239+
.with(fmt::layer().json())
240+
.with(env_filter)
241+
.try_init();
242+
} else {
243+
let _ = tracing_subscriber::registry()
244+
.with(fmt::layer())
245+
.with(env_filter)
246+
.try_init();
247+
}
248+
249+
log_panics::init();
250+
});
251+
}

0 commit comments

Comments
 (0)