From ee6524a75f8326b6f9af4ca611568c0996a83ea7 Mon Sep 17 00:00:00 2001 From: rishflab Date: Fri, 10 Sep 2021 15:35:59 +1000 Subject: [PATCH] Timestamp logs by default on the ASB Disable timestamps using the command line flag --- CHANGELOG.md | 7 ++-- swap/src/asb/command.rs | 78 +++++++++++++++++++++++++---------------- swap/src/bin/asb.rs | 4 +-- 3 files changed, 55 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 471c65e4..fa4731ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Timestamping can now be enabled using the `timestamp` command line argument to the ASB. - JSON logs and ASB output in an interactive terminal are no longer timestamped by default. +- Timestamping is now enabled by default even when the ASB is not run inside an interactive terminal. - The `cancel`, `refund` and `punish` subcommands in ASB and CLI are run with the `--force` by default and the `--force` option has been removed. The force flag was used to ignore blockheight and protocol state checks. Users can still restart a swap with these checks using the `resume` subcommand. +### Added + +- Added a `disable-timestamp` flag to the ASB that disables timestamps from logs. + ## [0.8.3] - 2021-09-03 ### Fixed diff --git a/swap/src/asb/command.rs b/swap/src/asb/command.rs index 542be5e2..63c0594c 100644 --- a/swap/src/asb/command.rs +++ b/swap/src/asb/command.rs @@ -19,7 +19,7 @@ where let args = RawArguments::from_clap(&matches); let json = args.json; - let timestamp = args.timestamp; + let disable_timestamp = args.disable_timestamp; let testnet = args.testnet; let config = args.config; let command: RawCommand = args.cmd; @@ -28,7 +28,7 @@ where RawCommand::Start { resume_only } => Arguments { testnet, json, - timestamp, + disable_timestamp, config_path: config_path(config, testnet)?, env_config: env_config(testnet), cmd: Command::Start { resume_only }, @@ -36,7 +36,7 @@ where RawCommand::History => Arguments { testnet, json, - timestamp, + disable_timestamp, config_path: config_path(config, testnet)?, env_config: env_config(testnet), cmd: Command::History, @@ -44,7 +44,7 @@ where RawCommand::WithdrawBtc { amount, address } => Arguments { testnet, json, - timestamp, + disable_timestamp, config_path: config_path(config, testnet)?, env_config: env_config(testnet), cmd: Command::WithdrawBtc { @@ -55,7 +55,7 @@ where RawCommand::Balance => Arguments { testnet, json, - timestamp, + disable_timestamp, config_path: config_path(config, testnet)?, env_config: env_config(testnet), cmd: Command::Balance, @@ -66,7 +66,7 @@ where }) => Arguments { testnet, json, - timestamp, + disable_timestamp, config_path: config_path(config, testnet)?, env_config: env_config(testnet), cmd: Command::Redeem { @@ -80,7 +80,7 @@ where }) => Arguments { testnet, json, - timestamp, + disable_timestamp, config_path: config_path(config, testnet)?, env_config: env_config(testnet), cmd: Command::Cancel { swap_id }, @@ -90,7 +90,7 @@ where }) => Arguments { testnet, json, - timestamp, + disable_timestamp, config_path: config_path(config, testnet)?, env_config: env_config(testnet), cmd: Command::Refund { swap_id }, @@ -100,7 +100,7 @@ where }) => Arguments { testnet, json, - timestamp, + disable_timestamp, config_path: config_path(config, testnet)?, env_config: env_config(testnet), cmd: Command::Punish { swap_id }, @@ -108,7 +108,7 @@ where RawCommand::ManualRecovery(ManualRecovery::SafelyAbort { swap_id }) => Arguments { testnet, json, - timestamp, + disable_timestamp, config_path: config_path(config, testnet)?, env_config: env_config(testnet), cmd: Command::SafelyAbort { swap_id }, @@ -168,7 +168,7 @@ pub struct BitcoinAddressNetworkMismatch { pub struct Arguments { pub testnet: bool, pub json: bool, - pub timestamp: bool, + pub disable_timestamp: bool, pub config_path: PathBuf, pub env_config: env::Config, pub cmd: Command, @@ -223,10 +223,10 @@ pub struct RawArguments { #[structopt( short, - long = "timestamp", - help = "Adds a timestamp to the log messages" + long = "disable-timestamp", + help = "Disable timestamping of log messages" )] - pub timestamp: bool, + pub disable_timestamp: bool, #[structopt( long = "config", @@ -344,7 +344,7 @@ mod tests { let expected_args = Arguments { testnet: false, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_mainnet_conf_path, env_config: mainnet_env_config, cmd: Command::Start { resume_only: false }, @@ -362,7 +362,7 @@ mod tests { let expected_args = Arguments { testnet: false, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_mainnet_conf_path, env_config: mainnet_env_config, cmd: Command::History, @@ -380,7 +380,7 @@ mod tests { let expected_args = Arguments { testnet: false, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_mainnet_conf_path, env_config: mainnet_env_config, cmd: Command::Balance, @@ -402,7 +402,7 @@ mod tests { let expected_args = Arguments { testnet: false, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_mainnet_conf_path, env_config: mainnet_env_config, cmd: Command::WithdrawBtc { @@ -429,7 +429,7 @@ mod tests { let expected_args = Arguments { testnet: false, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_mainnet_conf_path, env_config: mainnet_env_config, cmd: Command::Cancel { @@ -455,7 +455,7 @@ mod tests { let expected_args = Arguments { testnet: false, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_mainnet_conf_path, env_config: mainnet_env_config, cmd: Command::Refund { @@ -481,7 +481,7 @@ mod tests { let expected_args = Arguments { testnet: false, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_mainnet_conf_path, env_config: mainnet_env_config, cmd: Command::Punish { @@ -507,7 +507,7 @@ mod tests { let expected_args = Arguments { testnet: false, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_mainnet_conf_path, env_config: mainnet_env_config, cmd: Command::SafelyAbort { @@ -527,7 +527,7 @@ mod tests { let expected_args = Arguments { testnet: true, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_testnet_conf_path, env_config: testnet_env_config, cmd: Command::Start { resume_only: false }, @@ -545,7 +545,7 @@ mod tests { let expected_args = Arguments { testnet: true, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_testnet_conf_path, env_config: testnet_env_config, cmd: Command::History, @@ -563,7 +563,7 @@ mod tests { let expected_args = Arguments { testnet: true, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_testnet_conf_path, env_config: testnet_env_config, cmd: Command::Balance, @@ -587,7 +587,7 @@ mod tests { let expected_args = Arguments { testnet: true, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_testnet_conf_path, env_config: testnet_env_config, cmd: Command::WithdrawBtc { @@ -614,7 +614,7 @@ mod tests { let expected_args = Arguments { testnet: true, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_testnet_conf_path, env_config: testnet_env_config, cmd: Command::Cancel { @@ -641,7 +641,7 @@ mod tests { let expected_args = Arguments { testnet: true, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_testnet_conf_path, env_config: testnet_env_config, cmd: Command::Refund { @@ -668,7 +668,7 @@ mod tests { let expected_args = Arguments { testnet: true, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_testnet_conf_path, env_config: testnet_env_config, cmd: Command::Punish { @@ -695,7 +695,7 @@ mod tests { let expected_args = Arguments { testnet: true, json: false, - timestamp: false, + disable_timestamp: false, config_path: default_testnet_conf_path, env_config: testnet_env_config, cmd: Command::SafelyAbort { @@ -706,6 +706,24 @@ mod tests { assert_eq!(expected_args, args); } + #[test] + fn ensure_disable_timestamp_mapping() { + let default_mainnet_conf_path = env::Mainnet::getConfigFileDefaults().unwrap().config_path; + let mainnet_env_config = env::Mainnet::get_config(); + + let raw_ars = vec![BINARY_NAME, "--disable-timestamp", "start"]; + let expected_args = Arguments { + testnet: false, + json: false, + disable_timestamp: true, + config_path: default_mainnet_conf_path, + env_config: mainnet_env_config, + cmd: Command::Start { resume_only: false }, + }; + let args = parse_args(raw_ars).unwrap(); + assert_eq!(expected_args, args); + } + #[test] fn given_user_provides_config_path_then_no_default_config_path_returned() { let cp = PathBuf::from_str("/some/config/path").unwrap(); diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index 79cd71e2..ae3ead70 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -45,7 +45,7 @@ async fn main() -> Result<()> { let Arguments { testnet, json, - timestamp, + disable_timestamp, config_path, env_config, cmd, @@ -67,7 +67,7 @@ async fn main() -> Result<()> { } }; - asb::tracing::init(LevelFilter::DEBUG, json, timestamp).expect("initialize tracing"); + asb::tracing::init(LevelFilter::DEBUG, json, !disable_timestamp).expect("initialize tracing"); let config = match read_config(config_path.clone())? { Ok(config) => config,