From baa5711de8a13c75a4d406a76d49e3dec124a6b0 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 14 Jul 2021 17:25:21 +0200 Subject: Add logging Signed-off-by: Matthias Beyer --- Cargo.toml | 3 +++ src/backend/backend.rs | 2 ++ src/main.rs | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 80cc7d2..9ab8ae9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,9 @@ edition = "2018" # TODO: Replace with thiserror anyhow = "1" +env_logger = "0.8" +log = "0.4" + async-trait = "0.1" chrono = "0.4" cid = "0.6" diff --git a/src/backend/backend.rs b/src/backend/backend.rs index 2f8bdbf..c398c97 100644 --- a/src/backend/backend.rs +++ b/src/backend/backend.rs @@ -20,12 +20,14 @@ impl IpfsEmbedBackend { impl daglib::DagBackend for IpfsEmbedBackend { async fn get(&self, id: Id) -> Result> { + log::trace!("GET {:?}", id); let block = self.ipfs.fetch(id.as_ref(), self.ipfs.peers()).await?; let node = block.decode::()?; Ok(Some((id, node))) } async fn put(&mut self, node: Node) -> Result { + log::trace!("PUT {:?}", node); let block = libipld::block::Block::encode(libipld::cbor::DagCborCodec, libipld::multihash::Code::Blake3_256, &node)?; let cid = Id::from(block.cid().clone()); self.ipfs diff --git a/src/main.rs b/src/main.rs index 8f0d938..4041c3f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,8 +20,10 @@ mod profile; #[tokio::main] async fn main() -> Result<()> { + let _ = env_logger::try_init()?; let app = crate::cli::app(); + log::info!("Booting backend"); let mut backend = { // Testing configuration for the IPFS node in the backend. @@ -59,6 +61,7 @@ async fn main() -> Result<()> { }; crate::backend::IpfsEmbedBackend::new_with_config(ipfs_configuration).await? }; + log::info!("Backend booted successfully"); backend.ipfs() .listen_on("/ip4/127.0.0.1/tcp/0".parse()?)? @@ -68,6 +71,7 @@ async fn main() -> Result<()> { match app.get_matches().subcommand() { ("create-profile", Some(mtch)) => { + log::info!("Creating profile"); let payload = mtch .value_of("content") .map(String::from) @@ -75,11 +79,14 @@ async fn main() -> Result<()> { .unwrap(); // Safe by clap let payload_cid = backend.write_payload(&payload).await?; + log::info!("Payload written as {}", payload_cid); let node = crate::backend::Node::new(crate::consts::v1(), vec![], payload_cid); + log::info!("Writing node for payload"); let id = backend.put(node).await?; println!("id = {}", id.as_ref()); + log::info!("Creating profile finished"); Ok(()) }, @@ -113,13 +120,17 @@ async fn main() -> Result<()> { .map(crate::backend::Id::from) .unwrap(); // Safe by clap + log::info!("Fetching {} from backend", head.as_ref()); let (id, node) = backend .get(head.clone()) .await? .ok_or_else(|| anyhow!("Not found: {:?}", head))?; + log::info!("Fetching payload of {} ({}) from backend", head.as_ref(), node.payload_id()); let payload = backend.ipfs().fetch(node.payload_id(), backend.ipfs().peers()).await?; + log::debug!("Fetched payload, now decoding..."); let payload = payload.decode::()?; + log::debug!("Decoding successful"); println!("id = {}", id.as_ref()); println!("node = {:?}", node); -- cgit v1.2.3