From b6e3f9a8a4332f798ac3067eff2317e8fda5ea9e Mon Sep 17 00:00:00 2001 From: "Franz Heinzmann (Frando)" Date: Tue, 16 Apr 2024 01:28:36 +0200 Subject: [PATCH] fix: better logging for iroh-dns-server --- iroh-dns-server/src/config.rs | 10 ++++++++-- iroh-dns-server/src/store/signed_packets.rs | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/iroh-dns-server/src/config.rs b/iroh-dns-server/src/config.rs index 4f50fbc46b..d68f7663cc 100644 --- a/iroh-dns-server/src/config.rs +++ b/iroh-dns-server/src/config.rs @@ -1,13 +1,15 @@ //! Configuration for the server -use anyhow::{anyhow, Context, Result}; -use serde::{Deserialize, Serialize}; use std::{ env, net::{IpAddr, Ipv4Addr, SocketAddr}, path::{Path, PathBuf}, }; +use anyhow::{anyhow, Context, Result}; +use serde::{Deserialize, Serialize}; +use tracing::info; + use crate::{ dns::DnsConfig, http::{CertMode, HttpConfig, HttpsConfig}, @@ -62,6 +64,10 @@ impl MetricsConfig { impl Config { /// Load the config from a file. pub async fn load(path: impl AsRef) -> Result { + info!( + "loading config file from {}", + path.as_ref().to_string_lossy() + ); let s = tokio::fs::read_to_string(path.as_ref()) .await .with_context(|| format!("failed to read {}", path.as_ref().to_string_lossy()))?; diff --git a/iroh-dns-server/src/store/signed_packets.rs b/iroh-dns-server/src/store/signed_packets.rs index 1ed03598d2..dc579975fc 100644 --- a/iroh-dns-server/src/store/signed_packets.rs +++ b/iroh-dns-server/src/store/signed_packets.rs @@ -1,9 +1,10 @@ use std::path::Path; -use anyhow::Result; +use anyhow::{Context, Result}; use iroh_metrics::inc; use pkarr::SignedPacket; use redb::{backends::InMemoryBackend, Database, ReadableTable, TableDefinition}; +use tracing::info; use crate::{metrics::Metrics, util::PublicKeyBytes}; @@ -18,14 +19,24 @@ pub struct SignedPacketStore { impl SignedPacketStore { pub fn persistent(path: impl AsRef) -> Result { - if let Some(parent) = path.as_ref().parent() { - std::fs::create_dir_all(parent)?; + let path = path.as_ref(); + info!("loading packet database from {}", path.to_string_lossy()); + if let Some(parent) = path.parent() { + std::fs::create_dir_all(parent).with_context(|| { + format!( + "failed to create database directory at {}", + path.to_string_lossy() + ) + })?; } - let db = Database::builder().create(path)?; + let db = Database::builder() + .create(path) + .context("failed to open packet database")?; Self::open(db) } pub fn in_memory() -> Result { + info!("using in-memory packet database"); let db = Database::builder().create_with_backend(InMemoryBackend::new())?; Self::open(db) }