Skip to content

Commit b6451be

Browse files
authored
Log using tracing (#16)
* Log using tracing * Clippy * Add missing file
1 parent eaa8d97 commit b6451be

File tree

11 files changed

+36
-34
lines changed

11 files changed

+36
-34
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ 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 = "0.4"
1716
rand = "0.8"
1817
serde = { version = "1.0.192", default-features = false, features = ["alloc", "derive"] }
1918
serde_json = { version = "1.0", default-features = false }
2019
tempfile = "3.8"
2120
tokio = { version = "1.39", features = ["full"] }
2221
toml = "0.8.0"
22+
tracing = { version = "0.1.40", default-features = false }
2323

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

src/batch_prover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::time::SystemTime;
22

33
use anyhow::bail;
4-
use log::debug;
54
use tokio::time::{sleep, Duration};
5+
use tracing::debug;
66

77
use super::{config::FullBatchProverConfig, Result};
88
use crate::node::Node;

src/bitcoin.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use bitcoin::Address;
1111
use bitcoincore_rpc::{json::AddressType::Bech32m, Auth, Client, RpcApi};
1212
use futures::TryStreamExt;
1313
use tokio::{process::Command, sync::OnceCell, time::sleep};
14+
use tracing::{debug, info, trace};
1415

1516
use super::{
1617
config::BitcoinConfig,
@@ -105,7 +106,7 @@ impl BitcoinNode {
105106

106107
while start.elapsed() < timeout_duration {
107108
if !self.is_process_running().await? {
108-
println!("Bitcoin daemon has stopped successfully");
109+
info!("Bitcoin daemon has stopped successfully");
109110
return Ok(());
110111
}
111112
sleep(Duration::from_millis(200)).await;
@@ -182,7 +183,7 @@ impl NodeT for BitcoinNode {
182183

183184
fn spawn(config: &Self::Config) -> Result<SpawnOutput> {
184185
let args = config.args();
185-
println!("Running bitcoind with args : {args:?}");
186+
debug!("Running bitcoind with args : {args:?}");
186187

187188
Command::new("bitcoind")
188189
.args(&args)
@@ -198,7 +199,7 @@ impl NodeT for BitcoinNode {
198199
}
199200

200201
async fn wait_for_ready(&self, timeout: Option<Duration>) -> Result<()> {
201-
println!("Waiting for ready");
202+
trace!("Waiting for ready");
202203
let start = Instant::now();
203204
let timeout = timeout.unwrap_or(Duration::from_secs(30));
204205
while start.elapsed() < timeout {
@@ -210,7 +211,7 @@ impl NodeT for BitcoinNode {
210211
}
211212
tokio::time::sleep(Duration::from_millis(500)).await;
212213
}
213-
anyhow::bail!("Node failed to become ready within the specified timeout")
214+
bail!("Node failed to become ready within the specified timeout")
214215
}
215216

216217
fn client(&self) -> &Self::Client {
@@ -249,7 +250,7 @@ impl Restart for BitcoinNode {
249250
.try_collect::<Vec<_>>()
250251
.await?;
251252
env.docker.remove_container(&output.id, None).await?;
252-
println!("Docker container {} succesfully removed", output.id);
253+
info!("Docker container {} succesfully removed", output.id);
253254
Ok(())
254255
}
255256
}
@@ -361,5 +362,5 @@ async fn wait_for_rpc_ready(client: &Client, timeout: Option<Duration>) -> Resul
361362
Err(_) => sleep(Duration::from_millis(500)).await,
362363
}
363364
}
364-
Err(anyhow::anyhow!("Timeout waiting for RPC to be ready"))
365+
bail!("Timeout waiting for RPC to be ready")
365366
}

src/citrea_config/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub fn from_toml_path<P: AsRef<std::path::Path>, R: serde::de::DeserializeOwned>
2121
let mut file = File::open(path)?;
2222
file.read_to_string(&mut contents)?;
2323
}
24-
log::debug!("Config file size: {} bytes", contents.len());
25-
log::trace!("Config file contents: {}", &contents);
24+
tracing::debug!("Config file size: {} bytes", contents.len());
25+
tracing::trace!("Config file contents: {}", &contents);
2626

2727
let result: R = toml::from_str(&contents)?;
2828

src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use jsonrpsee::{
66
http_client::{HttpClient, HttpClientBuilder},
77
rpc_params,
88
};
9-
use log::debug;
109
use sov_ledger_rpc::client::RpcClient;
1110
use sov_rollup_interface::rpc::{
1211
SequencerCommitmentResponse, SoftConfirmationResponse, VerifiedProofResponse,
1312
};
1413
use tokio::time::sleep;
14+
use tracing::trace;
1515

1616
pub struct Client {
1717
client: HttpClient,
@@ -97,7 +97,7 @@ impl Client {
9797
let start = SystemTime::now();
9898
let timeout = timeout.unwrap_or(Duration::from_secs(30)); // Default 30 seconds timeout
9999
loop {
100-
debug!("Waiting for soft confirmation {}", num);
100+
trace!("Waiting for soft confirmation {}", num);
101101
let latest_block = self.client.get_head_soft_confirmation_height().await?;
102102

103103
if latest_block >= num {

src/docker.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use bollard::{
1717
};
1818
use futures::StreamExt;
1919
use tokio::{fs::File, io::AsyncWriteExt, task::JoinHandle};
20+
use tracing::{debug, info};
2021

2122
use super::{config::DockerConfig, traits::SpawnOutput, utils::generate_test_id};
2223
use crate::traits::ContainerSpawnOutput;
@@ -91,7 +92,7 @@ impl DockerEnv {
9192
}
9293

9394
pub async fn spawn(&self, config: DockerConfig) -> Result<SpawnOutput> {
94-
println!("Spawning docker with config {config:#?}");
95+
debug!("Spawning docker with config {config:#?}");
9596
let exposed_ports: HashMap<String, HashMap<(), ()>> = config
9697
.ports
9798
.iter()
@@ -146,9 +147,6 @@ impl DockerEnv {
146147
.context("Image not specified in config")?;
147148
self.ensure_image_exists(image).await?;
148149

149-
// println!("options :{options:?}");
150-
// println!("config :{container_config:?}");
151-
152150
let container = self
153151
.docker
154152
.create_container::<String, String>(None, container_config)
@@ -196,7 +194,7 @@ impl DockerEnv {
196194
return Ok(());
197195
}
198196

199-
println!("Pulling image: {image}");
197+
info!("Pulling image: {image}...");
200198
let options = Some(CreateImageOptions {
201199
from_image: image,
202200
..Default::default()
@@ -214,7 +212,7 @@ impl DockerEnv {
214212
Err(e) => return Err(anyhow::anyhow!("Failed to pull image: {}", e)),
215213
}
216214
}
217-
println!("Image succesfully pulled");
215+
info!("Image succesfully pulled");
218216

219217
Ok(())
220218
}

src/framework.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{future::Future, sync::Arc};
22

33
use bitcoincore_rpc::RpcApi;
4+
use tracing::{debug, info};
45

56
use super::{
67
bitcoin::BitcoinNodeCluster,
@@ -119,13 +120,13 @@ impl TestFramework {
119120

120121
pub fn show_log_paths(&self) {
121122
if self.show_logs {
122-
println!(
123+
info!(
123124
"Logs available at {}",
124125
self.ctx.config.test_case.dir.display()
125126
);
126127

127128
for node in self.get_nodes_as_log_provider() {
128-
println!(
129+
info!(
129130
"{} logs available at : {}",
130131
node.kind(),
131132
node.log_path().display()
@@ -135,14 +136,14 @@ impl TestFramework {
135136
}
136137

137138
pub fn dump_log(&self) -> Result<()> {
138-
println!("Dumping logs:");
139+
debug!("Dumping logs:");
139140

140141
let n_lines = std::env::var("TAIL_N_LINES")
141142
.ok()
142143
.and_then(|v| v.parse::<usize>().ok())
143144
.unwrap_or(25);
144145
for node in self.get_nodes_as_log_provider() {
145-
println!("{} logs (last {n_lines} lines):", node.kind());
146+
debug!("{} logs (last {n_lines} lines):", node.kind());
146147
if let Err(e) = tail_file(&node.log_path(), n_lines) {
147148
eprint!("{e}");
148149
}
@@ -151,34 +152,34 @@ impl TestFramework {
151152
}
152153

153154
pub async fn stop(&mut self) -> Result<()> {
154-
println!("Stopping framework...");
155+
info!("Stopping framework...");
155156

156157
if let Some(sequencer) = &mut self.sequencer {
157158
let _ = sequencer.stop().await;
158-
println!("Successfully stopped sequencer");
159+
info!("Successfully stopped sequencer");
159160
}
160161

161162
if let Some(batch_prover) = &mut self.batch_prover {
162163
let _ = batch_prover.stop().await;
163-
println!("Successfully stopped batch_prover");
164+
info!("Successfully stopped batch_prover");
164165
}
165166

166167
if let Some(light_client_prover) = &mut self.light_client_prover {
167168
let _ = light_client_prover.stop().await;
168-
println!("Successfully stopped light_client_prover");
169+
info!("Successfully stopped light_client_prover");
169170
}
170171

171172
if let Some(full_node) = &mut self.full_node {
172173
let _ = full_node.stop().await;
173-
println!("Successfully stopped full_node");
174+
info!("Successfully stopped full_node");
174175
}
175176

176177
let _ = self.bitcoin_nodes.stop_all().await;
177-
println!("Successfully stopped bitcoin nodes");
178+
info!("Successfully stopped bitcoin nodes");
178179

179180
if let Some(docker) = self.ctx.docker.as_ref() {
180181
let _ = docker.cleanup().await;
181-
println!("Successfully cleaned docker");
182+
info!("Successfully cleaned docker");
182183
}
183184

184185
Ok(())

src/light_client_prover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::time::SystemTime;
22

33
use anyhow::bail;
4-
use log::debug;
54
use tokio::time::{sleep, Duration};
5+
use tracing::debug;
66

77
use super::{config::FullLightClientProverConfig, Result};
88
use crate::node::Node;

src/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use std::{
88

99
use anyhow::{bail, Context};
1010
use async_trait::async_trait;
11-
use log::debug;
1211
use serde::Serialize;
1312
use tokio::{
1413
process::Command,
1514
time::{sleep, Instant},
1615
};
16+
use tracing::trace;
1717

1818
use crate::{
1919
client::Client,
@@ -130,7 +130,7 @@ impl<C: Config> Node<C> {
130130
let start = SystemTime::now();
131131
let timeout = timeout.unwrap_or(Duration::from_secs(30)); // Default 30 seconds timeout
132132
loop {
133-
debug!("Waiting for soft confirmation {}", num);
133+
trace!("Waiting for soft confirmation {}", num);
134134
let latest_block = self
135135
.client
136136
.ledger_get_head_soft_confirmation_height()

src/traits.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use anyhow::Context;
44
use async_trait::async_trait;
55
use bollard::{container::StopContainerOptions, Docker};
66
use tokio::process::Child;
7+
use tracing::info;
78

89
use super::Result;
910
use crate::node::NodeKind;
@@ -45,7 +46,7 @@ pub trait NodeT: Send {
4546
Ok(())
4647
}
4748
SpawnOutput::Container(ContainerSpawnOutput { id, .. }) => {
48-
println!("Stopping container {id}");
49+
info!("Stopping container {id}");
4950
let docker =
5051
Docker::connect_with_local_defaults().context("Failed to connect to Docker")?;
5152
docker

0 commit comments

Comments
 (0)