From 8fb0c1ff93ceb2552b596277ce60ec4de91eb195 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Thu, 17 Oct 2024 00:26:36 +0530 Subject: [PATCH] chore: more logging for the cli --- autonomi-cli/src/actions/connect.rs | 2 ++ autonomi-cli/src/actions/download.rs | 2 ++ autonomi-cli/src/commands/file.rs | 5 +++++ autonomi-cli/src/commands/register.rs | 16 +++++++++++++++- autonomi/src/client/mod.rs | 2 ++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/autonomi-cli/src/actions/connect.rs b/autonomi-cli/src/actions/connect.rs index 9eccb3bbfb..cfe971d14e 100644 --- a/autonomi-cli/src/actions/connect.rs +++ b/autonomi-cli/src/actions/connect.rs @@ -24,10 +24,12 @@ pub async fn connect_to_network(peers: Vec) -> Result { match Client::connect(&peers).await { Ok(client) => { + info!("Connected to the Network"); progress_bar.finish_with_message("Connected to the Network"); Ok(client) } Err(e) => { + error!("Failed to connect to the network: {e}"); progress_bar.finish_with_message("Failed to connect to the network"); bail!("Failed to connect to the network: {e}") } diff --git a/autonomi-cli/src/actions/download.rs b/autonomi-cli/src/actions/download.rs index ba004930e3..cd8e37615e 100644 --- a/autonomi-cli/src/actions/download.rs +++ b/autonomi-cli/src/actions/download.rs @@ -41,12 +41,14 @@ pub async fn download(addr: &str, dest_path: &str, client: &mut Client) -> Resul progress_bar.finish_and_clear(); if all_errs.is_empty() { + info!("Successfully downloaded data at: {addr}"); println!("Successfully downloaded data at: {addr}"); Ok(()) } else { let err_no = all_errs.len(); eprintln!("{err_no} errors while downloading data at: {addr}"); eprintln!("{all_errs:#?}"); + error!("Errors while downloading data at {addr}: {all_errs:#?}"); Err(eyre!("Errors while downloading data")) } } diff --git a/autonomi-cli/src/commands/file.rs b/autonomi-cli/src/commands/file.rs index d99a848214..f3c49d8cb4 100644 --- a/autonomi-cli/src/commands/file.rs +++ b/autonomi-cli/src/commands/file.rs @@ -17,6 +17,7 @@ pub async fn cost(file: &str, peers: Vec) -> Result<()> { let client = crate::actions::connect_to_network(peers).await?; println!("Getting upload cost..."); + info!("Calculating cost for file: {file}"); let cost = client .file_cost(&PathBuf::from(file)) .await @@ -24,6 +25,7 @@ pub async fn cost(file: &str, peers: Vec) -> Result<()> { println!("Estimate cost to upload file: {file}"); println!("Total cost: {cost}"); + info!("Total cost: {cost} for file: {file}"); Ok(()) } pub async fn upload(file: &str, peers: Vec) -> Result<()> { @@ -33,6 +35,7 @@ pub async fn upload(file: &str, peers: Vec) -> Result<()> { let (upload_summary_thread, upload_completed_tx) = collect_upload_summary(event_receiver); println!("Uploading data to network..."); + info!("Uploading file: {file}"); let xor_name = client .dir_upload(PathBuf::from(file), &wallet) @@ -42,6 +45,7 @@ pub async fn upload(file: &str, peers: Vec) -> Result<()> { println!("Successfully uploaded: {file}"); println!("At address: {addr}"); + info!("Successfully uploaded: {file} at address: {addr}"); if let Ok(()) = upload_completed_tx.send(()) { let summary = upload_summary_thread.await?; if summary.record_count == 0 { @@ -50,6 +54,7 @@ pub async fn upload(file: &str, peers: Vec) -> Result<()> { println!("Number of chunks uploaded: {}", summary.record_count); println!("Total cost: {} AttoTokens", summary.tokens_spent); } + info!("Summary for upload of file {file} at {addr:?}: {summary:?}"); } Ok(()) diff --git a/autonomi-cli/src/commands/register.rs b/autonomi-cli/src/commands/register.rs index d559e6cc55..b5be4f0230 100644 --- a/autonomi-cli/src/commands/register.rs +++ b/autonomi-cli/src/commands/register.rs @@ -21,6 +21,7 @@ pub fn generate_key(overwrite: bool) -> Result<()> { // check if the key already exists let key_path = crate::keys::get_register_signing_key_path()?; if key_path.exists() && !overwrite { + error!("Register key already exists at: {key_path:?}"); return Err(eyre!("Register key already exists at: {}", key_path.display())) .with_suggestion(|| "if you want to overwrite the existing key, run the command with the --overwrite flag") .with_warning(|| "overwriting the existing key might result in loss of access to any existing registers created using that key"); @@ -30,6 +31,7 @@ pub fn generate_key(overwrite: bool) -> Result<()> { let key = RegisterSecretKey::random(); let path = crate::keys::create_register_signing_key_file(key) .wrap_err("Failed to create new register key")?; + info!("Created new register key at: {path:?}"); println!("✅ Created new register key at: {}", path.display()); Ok(()) } @@ -43,6 +45,7 @@ pub async fn cost(name: &str, peers: Vec) -> Result<()> { .register_cost(name.to_string(), register_key) .await .wrap_err("Failed to get cost for register")?; + info!("Estimated cost to create a register with name {name}: {cost}"); println!("✅ The estimated cost to create a register with name {name} is: {cost}"); Ok(()) } @@ -56,8 +59,10 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec let (upload_summary_thread, upload_completed_tx) = collect_upload_summary(event_receiver); println!("Creating register with name: {name}"); + info!("Creating register with name: {name}"); let register = if public { println!("With public write access"); + info!("With public write access"); let permissions = RegisterPermissions::new_anyone_can_write(); client .register_create_with_permissions( @@ -71,6 +76,7 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec .wrap_err("Failed to create register")? } else { println!("With private write access"); + info!("With private write access"); client .register_create( value.as_bytes().to_vec().into(), @@ -87,6 +93,7 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec println!("✅ Register created at address: {address}"); println!("With name: {name}"); println!("And initial value: [{value}]"); + info!("✅ Register created at address: {address} with name: {name}"); if let Ok(()) = upload_completed_tx.send(()) { let summary = upload_summary_thread.await?; @@ -95,6 +102,7 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec } else { println!("Total cost: {} AttoTokens", summary.tokens_spent); } + info!("Summary of register creation: {summary:?}"); } Ok(()) @@ -116,13 +124,16 @@ pub async fn edit(address: String, name: bool, value: &str, peers: Vec) -> Result<( }; println!("Getting register at address: {address}"); + info!("Getting register at address: {address}"); let register = client .register_get(address) .await @@ -157,6 +170,7 @@ pub async fn get(address: String, name: bool, peers: Vec) -> Result<( let values = register.values(); println!("✅ Register found at address: {address}"); + info!("Register found at address: {address}"); match values.as_slice() { [one] => println!("With value: [{:?}]", String::from_utf8_lossy(one)), _ => { diff --git a/autonomi/src/client/mod.rs b/autonomi/src/client/mod.rs index f19216fe84..df5dab4ec0 100644 --- a/autonomi/src/client/mod.rs +++ b/autonomi/src/client/mod.rs @@ -197,11 +197,13 @@ async fn handle_event_receiver( } /// Events that can be broadcasted by the client. +#[derive(Debug, Clone)] pub enum ClientEvent { UploadComplete(UploadSummary), } /// Summary of an upload operation. +#[derive(Debug, Clone)] pub struct UploadSummary { pub record_count: usize, pub tokens_spent: Amount,