diff --git a/swap/src/asb/command.rs b/swap/src/asb/command.rs index 9fcde941..0b5ecc06 100644 --- a/swap/src/asb/command.rs +++ b/swap/src/asb/command.rs @@ -44,6 +44,7 @@ where RawCommand::Logs { output_path, logs_dir: dir_path, + swap_id, redact, } => Arguments { testnet, @@ -54,6 +55,7 @@ where cmd: Command::Logs { logs_dir: dir_path, output_path, + swap_id, redact, }, }, @@ -216,6 +218,7 @@ pub enum Command { Logs { logs_dir: Option, output_path: Option, + swap_id: Option, redact: bool, }, WithdrawBtc { @@ -308,6 +311,12 @@ pub enum RawCommand { long = "redact" )] redact: bool, + #[structopt( + long = "swap-id", + help = "Filter for logs concerning this swap.", + long_help = "This checks whether each logging message contains the swap id. Some messages might be skipped when they don't contain the swap id even though they're relevant.", + )] + swap_id: Option }, #[structopt(about = "Prints the current config")] Config, diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index ad477846..ec099501 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -251,6 +251,7 @@ async fn main() -> Result<()> { Command::Logs { logs_dir, output_path, + swap_id, redact, } => { // use provided directory of default one @@ -299,6 +300,17 @@ async fn main() -> Result<()> { None => OutputChannel::Stdout(stdout()), }; + // conveniance method for checking whether we should filter a specific line + let filter_by_swap_id: Box bool> = match swap_id { + // if we should filter by swap id, check if the line contains the string + Some(swap_id) => { + let swap_id = swap_id.to_string(); + Box::new(move |line: &str| line.contains(&swap_id)) + } + // otherwise we let every line pass + None => Box::new(|_| true), + }; + // print all lines from every log file. TODO: sort files by date? for entry in log_files { // get the file path @@ -319,6 +331,11 @@ async fn main() -> Result<()> { // print each line, redacted if the flag is set while let Some(line) = lines.next_line().await? { + // check if we should filter this line + if !filter_by_swap_id(&line) { + continue; + } + let line = if redact { common::redact(&line) } else { line }; write_to_channel(&mut output_channel, &line).await?; // don't forget newlines