Timestamp logs by default on the ASB

Disable timestamps using the command line flag
This commit is contained in:
rishflab 2021-09-10 15:35:59 +10:00
parent e380052610
commit ee6524a75f
3 changed files with 55 additions and 34 deletions

View File

@ -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

View File

@ -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();

View File

@ -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,