mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-25 06:39:53 -04:00
add --swap-id option
This commit is contained in:
parent
8807db5314
commit
1b218f0895
2 changed files with 26 additions and 0 deletions
|
@ -44,6 +44,7 @@ where
|
||||||
RawCommand::Logs {
|
RawCommand::Logs {
|
||||||
output_path,
|
output_path,
|
||||||
logs_dir: dir_path,
|
logs_dir: dir_path,
|
||||||
|
swap_id,
|
||||||
redact,
|
redact,
|
||||||
} => Arguments {
|
} => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
|
@ -54,6 +55,7 @@ where
|
||||||
cmd: Command::Logs {
|
cmd: Command::Logs {
|
||||||
logs_dir: dir_path,
|
logs_dir: dir_path,
|
||||||
output_path,
|
output_path,
|
||||||
|
swap_id,
|
||||||
redact,
|
redact,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -216,6 +218,7 @@ pub enum Command {
|
||||||
Logs {
|
Logs {
|
||||||
logs_dir: Option<PathBuf>,
|
logs_dir: Option<PathBuf>,
|
||||||
output_path: Option<PathBuf>,
|
output_path: Option<PathBuf>,
|
||||||
|
swap_id: Option<Uuid>,
|
||||||
redact: bool,
|
redact: bool,
|
||||||
},
|
},
|
||||||
WithdrawBtc {
|
WithdrawBtc {
|
||||||
|
@ -308,6 +311,12 @@ pub enum RawCommand {
|
||||||
long = "redact"
|
long = "redact"
|
||||||
)]
|
)]
|
||||||
redact: bool,
|
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")]
|
#[structopt(about = "Prints the current config")]
|
||||||
Config,
|
Config,
|
||||||
|
|
|
@ -251,6 +251,7 @@ async fn main() -> Result<()> {
|
||||||
Command::Logs {
|
Command::Logs {
|
||||||
logs_dir,
|
logs_dir,
|
||||||
output_path,
|
output_path,
|
||||||
|
swap_id,
|
||||||
redact,
|
redact,
|
||||||
} => {
|
} => {
|
||||||
// use provided directory of default one
|
// use provided directory of default one
|
||||||
|
@ -299,6 +300,17 @@ async fn main() -> Result<()> {
|
||||||
None => OutputChannel::Stdout(stdout()),
|
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?
|
// print all lines from every log file. TODO: sort files by date?
|
||||||
for entry in log_files {
|
for entry in log_files {
|
||||||
// get the file path
|
// get the file path
|
||||||
|
@ -319,6 +331,11 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
// print each line, redacted if the flag is set
|
// print each line, redacted if the flag is set
|
||||||
while let Some(line) = lines.next_line().await? {
|
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 };
|
let line = if redact { common::redact(&line) } else { line };
|
||||||
write_to_channel(&mut output_channel, &line).await?;
|
write_to_channel(&mut output_channel, &line).await?;
|
||||||
// don't forget newlines
|
// don't forget newlines
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue