diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-07-14 17:25:21 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-07-14 17:25:21 +0200 |
commit | baa5711de8a13c75a4d406a76d49e3dec124a6b0 (patch) | |
tree | 43c4d301d4e7717e10c88687a735e412b4b72863 | |
parent | c05a0c9cfc91a9847f122851234b5e850d04807d (diff) |
Add logging
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/backend/backend.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 11 |
3 files changed, 16 insertions, 0 deletions
@@ -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<Id, Node> for IpfsEmbedBackend { async fn get(&self, id: Id) -> Result<Option<(Id, Node)>> { + log::trace!("GET {:?}", id); let block = self.ipfs.fetch(id.as_ref(), self.ipfs.peers()).await?; let node = block.decode::<libipld::cbor::DagCborCodec, crate::backend::Node>()?; Ok(Some((id, node))) } async fn put(&mut self, node: Node) -> Result<Id> { + 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::<libipld::cbor::DagCborCodec, crate::backend::Payload>()?; + log::debug!("Decoding successful"); println!("id = {}", id.as_ref()); println!("node = {:?}", node); |