Skip to content

Commit

Permalink
Set up tracing subscriber on TestFramework init
Browse files Browse the repository at this point in the history
  • Loading branch information
jfldde committed Oct 11, 2024
1 parent e85ecd3 commit 4867098
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ tempfile = "3.8"
tokio = { version = "1.39", features = ["full"] }
toml = "0.8.0"
tracing = { version = "0.1.40", default-features = false }
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json", "fmt"] }
log-panics = { version = "2", features = ["with-backtrace"] }

# Citrea dependencies
sov-ledger-rpc = { git = "https://github.com/chainwayxyz/citrea", rev = "82bf52d", default-features = false, features = ["client"] }
Expand Down
4 changes: 2 additions & 2 deletions src/batch_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::SystemTime;

use anyhow::bail;
use tokio::time::{sleep, Duration};
use tracing::debug;
use tracing::trace;

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

if latest_block >= height {
Expand Down
35 changes: 34 additions & 1 deletion src/framework.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{future::Future, sync::Arc};
use std::{
future::Future,
sync::{Arc, Once},
};

use bitcoincore_rpc::RpcApi;
use tracing::{debug, info};
Expand Down Expand Up @@ -53,6 +56,8 @@ async fn create_optional<T>(pred: bool, f: impl Future<Output = Result<T>>) -> R

impl TestFramework {
pub async fn new(config: TestConfig) -> Result<Self> {
setup_logging();

anyhow::ensure!(
config.test_case.n_nodes > 0,
"At least one bitcoin node has to be running"
Expand Down Expand Up @@ -219,3 +224,31 @@ impl TestFramework {
Ok(())
}
}

use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{fmt, EnvFilter};

static INIT: Once = Once::new();

fn setup_logging() {
INIT.call_once(|| {
let env_filter = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new("citrea_e2e=info"))
.unwrap();

if std::env::var("JSON_LOGS").is_ok() {
tracing_subscriber::registry()
.with(fmt::layer().json())
.with(env_filter)
.init();
} else {
tracing_subscriber::registry()
.with(fmt::layer())
.with(env_filter)
.init();
}

log_panics::init();
});
}

0 comments on commit 4867098

Please sign in to comment.