Skip to content

Commit 4867098

Browse files
committed
Set up tracing subscriber on TestFramework init
1 parent e85ecd3 commit 4867098

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ tempfile = "3.8"
2020
tokio = { version = "1.39", features = ["full"] }
2121
toml = "0.8.0"
2222
tracing = { version = "0.1.40", default-features = false }
23+
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json", "fmt"] }
24+
log-panics = { version = "2", features = ["with-backtrace"] }
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: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
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};
@@ -53,6 +56,8 @@ async fn create_optional<T>(pred: bool, f: impl Future<Output = Result<T>>) -> R
5356

5457
impl TestFramework {
5558
pub async fn new(config: TestConfig) -> Result<Self> {
59+
setup_logging();
60+
5661
anyhow::ensure!(
5762
config.test_case.n_nodes > 0,
5863
"At least one bitcoin node has to be running"
@@ -219,3 +224,31 @@ impl TestFramework {
219224
Ok(())
220225
}
221226
}
227+
228+
use tracing_subscriber::layer::SubscriberExt;
229+
use tracing_subscriber::util::SubscriberInitExt;
230+
use tracing_subscriber::{fmt, EnvFilter};
231+
232+
static INIT: Once = Once::new();
233+
234+
fn setup_logging() {
235+
INIT.call_once(|| {
236+
let env_filter = EnvFilter::try_from_default_env()
237+
.or_else(|_| EnvFilter::try_new("citrea_e2e=info"))
238+
.unwrap();
239+
240+
if std::env::var("JSON_LOGS").is_ok() {
241+
tracing_subscriber::registry()
242+
.with(fmt::layer().json())
243+
.with(env_filter)
244+
.init();
245+
} else {
246+
tracing_subscriber::registry()
247+
.with(fmt::layer())
248+
.with(env_filter)
249+
.init();
250+
}
251+
252+
log_panics::init();
253+
});
254+
}

0 commit comments

Comments
 (0)