mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-04-21 00:06:38 -04:00
add --swap-id option
This commit is contained in:
parent
8807db5314
commit
1b218f0895
@ -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<PathBuf>,
|
||||
output_path: Option<PathBuf>,
|
||||
swap_id: Option<Uuid>,
|
||||
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<Uuid>
|
||||
},
|
||||
#[structopt(about = "Prints the current config")]
|
||||
Config,
|
||||
|
@ -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<dyn Fn(&str) -> 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user