diff --git a/swap/src/asb/command.rs b/swap/src/asb/command.rs index f22e1500..48c44914 100644 --- a/swap/src/asb/command.rs +++ b/swap/src/asb/command.rs @@ -41,6 +41,17 @@ where env_config: env_config(testnet), cmd: Command::History, }, + RawCommand::Logs { dir_path, redact } => Arguments { + testnet, + json, + disable_timestamp, + config_path: config_path(config, testnet)?, + env_config: env_config(testnet), + cmd: Command::Logs { + path: dir_path, + redact, + }, + }, RawCommand::WithdrawBtc { amount, address } => Arguments { testnet, json, @@ -197,6 +208,10 @@ pub enum Command { }, History, Config, + Logs { + path: Option, + redact: bool, + }, WithdrawBtc { amount: Option, address: Address, @@ -270,6 +285,16 @@ pub enum RawCommand { }, #[structopt(about = "Prints swap-id and the state of each swap ever made.")] History, + #[structopt(about = "Prints all logging messages issued in the past.")] + Logs { + #[structopt(help = "Print the logs from this directory instead of the default one.")] + dir_path: Option, + #[structopt( + help = "Redact swap-ids, Bitcoin and Monero addresses.", + long = "redact" + )] + redact: bool, + }, #[structopt(about = "Prints the current config")] Config, #[structopt(about = "Allows withdrawing BTC from the internal Bitcoin wallet.")] diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index 7f7b3bf2..d51a007d 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -20,6 +20,7 @@ use libp2p::swarm::AddressScore; use libp2p::Swarm; use std::convert::TryInto; use std::env; +use std::fs::read_dir; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::sync::Arc; use structopt::clap; @@ -29,7 +30,7 @@ use swap::asb::config::{ initial_setup, query_user_for_initial_config, read_config, Config, ConfigNotInitialized, }; use swap::asb::{cancel, punish, redeem, refund, safely_abort, EventLoop, Finality, KrakenRate}; -use swap::common::check_latest_version; +use swap::common::{self, check_latest_version}; use swap::database::{open_db, AccessMode}; use swap::fs::system_data_dir; use swap::network::rendezvous::XmrBtcNamespace; @@ -38,6 +39,8 @@ use swap::protocol::alice::{run, AliceState}; use swap::seed::Seed; use swap::tor::AuthenticatedClient; use swap::{asb, bitcoin, kraken, monero, tor}; +use tokio::fs::File; +use tokio::io::{AsyncBufReadExt, BufReader}; use tracing_subscriber::filter::LevelFilter; const DEFAULT_WALLET_NAME: &str = "asb-wallet"; @@ -245,6 +248,31 @@ async fn main() -> Result<()> { let config_json = serde_json::to_string_pretty(&config)?; println!("{}", config_json); } + Command::Logs { path, redact } => { + // use provided directory of default one + let default_dir = system_data_dir()?.join("logs"); + let logs_dir = path.unwrap_or(default_dir); + + // go through each file and print it + let log_files = read_dir(&logs_dir)?; + + for entry in log_files { + let file_name = entry?.path(); + let file = File::open(&file_name).await?; + let buf_reader = BufReader::new(file); + let mut lines = buf_reader.lines(); + + println!("====reading log from file `{}`", &file_name.display()); + + // print each line, redacted if the flag is set + while let Some(line) = lines.next_line().await? { + let line = if redact { common::redact(&line) } else { line }; + println!("{}", line); + } + + println!("====no more log files found"); + } + } Command::WithdrawBtc { amount, address } => { let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; diff --git a/swap/src/proptest.rs b/swap/src/proptest.rs index 61b6db65..7ad8fb9a 100644 --- a/swap/src/proptest.rs +++ b/swap/src/proptest.rs @@ -2,7 +2,7 @@ use proptest::prelude::*; pub mod ecdsa_fun { use super::*; - use ecdsa_fun::fun::{Point, Scalar, G}; + use ::ecdsa_fun::fun::{Point, Scalar, G}; pub fn point() -> impl Strategy { scalar().prop_map(|mut scalar| Point::even_y_from_scalar_mul(G, &mut scalar).normalize()) @@ -17,8 +17,8 @@ pub mod ecdsa_fun { pub mod bitcoin { use super::*; - use bitcoin::util::bip32::ExtendedPrivKey; - use bitcoin::Network; + use ::bitcoin::util::bip32::ExtendedPrivKey; + use ::bitcoin::Network; pub fn extended_priv_key() -> impl Strategy { prop::array::uniform8(0..255u8).prop_filter_map("invalid secret key generated", |bytes| {