Don't import tracing's macros

Log statements end up getting changed constantly and having to clean
up imports after that is annoying, for example, if the last `info!`
in a file disappears, you end up with an unused import warning.

Fully qualifying tracing's macros prevents that and also communicates
clearly that we are using tracing and not log.
This commit is contained in:
Thomas Eizinger 2021-07-06 16:08:43 +10:00 committed by Daniel Karzel
parent fa1a5e6efb
commit 78480547d5
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E
4 changed files with 21 additions and 25 deletions

View File

@ -14,7 +14,6 @@ use std::ffi::OsStr;
use std::fs;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use tracing::info;
use url::Url;
pub trait GetDefaults {
@ -178,7 +177,7 @@ pub struct ConfigNotInitialized {}
pub fn read_config(config_path: PathBuf) -> Result<Result<Config, ConfigNotInitialized>> {
if config_path.exists() {
info!(
tracing::info!(
path = %config_path.display(),
"Using config file at",
);
@ -198,7 +197,7 @@ pub fn initial_setup(config_path: PathBuf, config: Config) -> Result<()> {
ensure_directory_exists(config_path.as_path())?;
fs::write(&config_path, toml)?;
info!(
tracing::info!(
path = %config_path.as_path().display(),
"Initial setup complete, config file created",
);

View File

@ -36,7 +36,6 @@ use swap::protocol::alice::run;
use swap::seed::Seed;
use swap::tor::AuthenticatedClient;
use swap::{asb, bitcoin, kraken, monero, tor};
use tracing::{debug, info, warn};
use tracing_subscriber::filter::LevelFilter;
const DEFAULT_WALLET_NAME: &str = "asb-wallet";
@ -90,7 +89,7 @@ async fn main() -> Result<()> {
));
}
info!(
tracing::info!(
db_folder = %config.data.dir.display(),
"Database and Seed will be stored in",
);
@ -110,17 +109,17 @@ async fn main() -> Result<()> {
let monero_wallet = init_monero_wallet(&config, env_config).await?;
let bitcoin_balance = bitcoin_wallet.balance().await?;
info!(%bitcoin_balance, "Initialized Bitcoin wallet");
tracing::info!(%bitcoin_balance, "Initialized Bitcoin wallet");
let monero_balance = monero_wallet.get_balance().await?;
if monero_balance == Amount::ZERO {
let monero_address = monero_wallet.get_main_address();
warn!(
tracing::warn!(
%monero_address,
"The Monero balance is 0, make sure to deposit funds at",
)
} else {
info!(%monero_balance, "Initialized Monero wallet");
tracing::info!(%monero_balance, "Initialized Monero wallet");
}
let kraken_price_updates = kraken::connect(config.maker.price_ticker_ws_url.clone())?;
@ -314,7 +313,7 @@ async fn init_bitcoin_wallet(
seed: &Seed,
env_config: swap::env::Config,
) -> Result<bitcoin::Wallet> {
debug!("Opening Bitcoin wallet");
tracing::debug!("Opening Bitcoin wallet");
let wallet_dir = config.data.dir.join("wallet");
let wallet = bitcoin::Wallet::new(
@ -336,7 +335,7 @@ async fn init_monero_wallet(
config: &Config,
env_config: swap::env::Config,
) -> Result<monero::Wallet> {
debug!("Opening Monero wallet");
tracing::debug!("Opening Monero wallet");
let wallet = monero::Wallet::open_or_create(
config.monero.wallet_rpc_url.clone(),
DEFAULT_WALLET_NAME.to_string(),

View File

@ -34,7 +34,6 @@ use swap::protocol::bob;
use swap::protocol::bob::Swap;
use swap::seed::Seed;
use swap::{bitcoin, cli, monero};
use tracing::{debug, error, info, warn};
use url::Url;
use uuid::Uuid;
@ -111,7 +110,7 @@ async fn main() -> Result<()> {
)
.await?;
info!(%amount, %fees, %swap_id, "Swapping");
tracing::info!(%amount, %fees, %swap_id, "Swapping");
db.insert_peer_id(swap_id, seller_peer_id).await?;
db.insert_monero_address(swap_id, monero_receive_address)
@ -242,9 +241,9 @@ async fn main() -> Result<()> {
match cancel {
Ok((txid, _)) => {
debug!("Cancel transaction successfully published with id {}", txid)
tracing::debug!("Cancel transaction successfully published with id {}", txid)
}
Err(cli::cancel::Error::CancelTimelockNotExpiredYet) => error!(
Err(cli::cancel::Error::CancelTimelockNotExpiredYet) => tracing::error!(
"The Cancel Transaction cannot be published yet, because the timelock has not expired. Please try again later"
),
}
@ -395,9 +394,9 @@ where
TS: Future<Output = Result<()>>,
FS: Fn() -> TS,
{
debug!("Requesting quote");
tracing::debug!("Requesting quote");
let bid_quote = bid_quote.await?;
info!(
tracing::info!(
price = %bid_quote.price,
minimum_amount = %bid_quote.min_quantity,
maximum_amount = %bid_quote.max_quantity,
@ -415,7 +414,7 @@ where
eprintln!("{}", qr_code(&deposit_address)?);
}
info!(
tracing::info!(
%deposit_address,
%max_giveable,
%minimum_amount,

View File

@ -8,7 +8,6 @@ use crate::{bitcoin, database, monero};
use anyhow::{bail, Context, Result};
use tokio::select;
use tokio::time::timeout;
use tracing::{error, info, warn};
use uuid::Uuid;
pub async fn run<LR>(swap: Swap, rate_service: LR) -> Result<AliceState>
@ -66,7 +65,7 @@ where
.latest_rate()
.map_or("NaN".to_string(), |rate| format!("{}", rate));
info!(%state, %rate, "Advancing state");
tracing::info!(%state, %rate, "Advancing state");
Ok(match state {
AliceState::Started { state3 } => {
@ -78,7 +77,7 @@ where
.await
{
Err(_) => {
info!(
tracing::info!(
minutes = %env_config.bitcoin_lock_mempool_timeout.as_secs_f64() / 60.0,
"TxLock lock was not seen in mempool in time",
);
@ -99,7 +98,7 @@ where
.await
{
Err(_) => {
info!(
tracing::info!(
confirmations_needed = %env_config.bitcoin_finality_confirmations,
minutes = %env_config.bitcoin_lock_confirmed_timeout.as_secs_f64() / 60.0,
"TxLock lock did not get enough confirmations in time",
@ -204,7 +203,7 @@ where
}
}
enc_sig = event_loop_handle.recv_encrypted_signature() => {
info!("Received encrypted signature");
tracing::info!("Received encrypted signature");
AliceState::EncSigLearned {
monero_wallet_restore_blockheight,
@ -232,7 +231,7 @@ where
}
},
Err(error) => {
error!(
tracing::error!(
"Publishing the redeem transaction failed. Error {:#}",
error
);
@ -248,7 +247,7 @@ where
}
},
Err(error) => {
error!(
tracing::error!(
"Constructing the redeem transaction failed. Attempting to wait for cancellation now. Error {:#}", error);
tx_lock_status
.wait_until_confirmed_with(state3.cancel_timelock)
@ -361,7 +360,7 @@ where
match punish {
Ok(_) => AliceState::BtcPunished,
Err(error) => {
warn!(
tracing::warn!(
"Falling back to refund because punish transaction failed. Error {:#}",
error
);