Skip to content

Commit

Permalink
logging: Add basic tracing::instruments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Aug 20, 2024
1 parent f1852ce commit 3d7680c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Client crate mocks the `Client` struct in `bitcoincore-rpc`.
use crate::ledger::Ledger;
use crate::{ledger::Ledger, utils};
use bitcoin::Txid;
use bitcoincore_rpc::{Auth, RpcApi};

Expand Down Expand Up @@ -47,7 +47,12 @@ impl RpcApiWrapper for Client {
/// Parameters must match `bitcoincore_rpc::Client::new()`. Only the `url`
/// is used for database identification. Authorization struct is not used
/// and can be a dummy value.
#[tracing::instrument]
fn new(url: &str, _auth: bitcoincore_rpc::Auth) -> bitcoincore_rpc::Result<Self> {
if let Err(e) = utils::initialize_logger() {
return Err(bitcoincore_rpc::Error::ReturnedError(e.to_string()));
};

Ok(Self {
ledger: Ledger::new(url),
})
Expand Down
2 changes: 2 additions & 0 deletions src/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ impl Ledger {
///
/// Panics if SQLite connection can't be established and initial query can't
/// be run.
#[tracing::instrument]
pub fn new(path: &str) -> Self {
let path = Ledger::get_database_path(path);
tracing::trace!("Creating database at path {path}");

let database = Connection::open(path.clone()).unwrap();

Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct MockRpc {
/// # Returns
///
/// URL on success, `std::io::Error` otherwise.
#[tracing::instrument]
pub async fn spawn_rpc_server(host: Option<&str>, port: Option<u16>) -> Result<SocketAddr, Error> {
let host = host.unwrap_or("127.0.0.1");
let port = match port {
Expand Down

0 comments on commit 3d7680c

Please sign in to comment.