diff --git a/swap/src/asb/tracing.rs b/swap/src/asb/tracing.rs index c21c1e70..3393cee3 100644 --- a/swap/src/asb/tracing.rs +++ b/swap/src/asb/tracing.rs @@ -1,18 +1,28 @@ +use std::path::Path; + use anyhow::Result; use tracing_subscriber::filter::LevelFilter; use tracing_subscriber::fmt::time::UtcTime; +use tracing_subscriber::fmt::writer::MakeWriterExt; use tracing_subscriber::FmtSubscriber; -pub fn init(level: LevelFilter, json_format: bool, timestamp: bool) -> Result<()> { +pub fn init( + level: LevelFilter, + json_format: bool, + timestamp: bool, + dir: impl AsRef, +) -> Result<()> { if level == LevelFilter::OFF { return Ok(()); } let is_terminal = atty::is(atty::Stream::Stderr); + let appender = tracing_appender::rolling::never(dir.as_ref(), "swap-all.log"); + let builder = FmtSubscriber::builder() .with_env_filter(format!("asb={},swap={}", level, level)) - .with_writer(std::io::stderr) + .with_writer(appender.and(std::io::stderr)) .with_ansi(is_terminal) .with_timer(UtcTime::rfc_3339()) .with_target(false); diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index 0f2f13b5..7f7b3bf2 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -31,6 +31,7 @@ use swap::asb::config::{ use swap::asb::{cancel, punish, redeem, refund, safely_abort, EventLoop, Finality, KrakenRate}; use swap::common::check_latest_version; use swap::database::{open_db, AccessMode}; +use swap::fs::system_data_dir; use swap::network::rendezvous::XmrBtcNamespace; use swap::network::swarm; use swap::protocol::alice::{run, AliceState}; @@ -72,7 +73,9 @@ async fn main() -> Result<()> { eprintln!("{}", e); } - asb::tracing::init(LevelFilter::DEBUG, json, !disable_timestamp).expect("initialize tracing"); + let log_dir = system_data_dir()?.join("logs"); + asb::tracing::init(LevelFilter::DEBUG, json, !disable_timestamp, log_dir) + .expect("initialize tracing"); let config = match read_config(config_path.clone())? { Ok(config) => config, diff --git a/swap/src/proptest.rs b/swap/src/proptest.rs index 7ad8fb9a..61b6db65 100644 --- a/swap/src/proptest.rs +++ b/swap/src/proptest.rs @@ -2,7 +2,7 @@ use proptest::prelude::*; pub mod ecdsa_fun { use super::*; - use ::ecdsa_fun::fun::{Point, Scalar, G}; + use ecdsa_fun::fun::{Point, Scalar, G}; pub fn point() -> impl Strategy { scalar().prop_map(|mut scalar| Point::even_y_from_scalar_mul(G, &mut scalar).normalize()) @@ -17,8 +17,8 @@ pub mod ecdsa_fun { pub mod bitcoin { use super::*; - use ::bitcoin::util::bip32::ExtendedPrivKey; - use ::bitcoin::Network; + use bitcoin::util::bip32::ExtendedPrivKey; + use bitcoin::Network; pub fn extended_priv_key() -> impl Strategy { prop::array::uniform8(0..255u8).prop_filter_map("invalid secret key generated", |bytes| { diff --git a/swap/src/seed.rs b/swap/src/seed.rs index aa363905..a17a7964 100644 --- a/swap/src/seed.rs +++ b/swap/src/seed.rs @@ -1,9 +1,9 @@ use crate::fs::ensure_directory_exists; -use ::bitcoin::secp256k1::constants::SECRET_KEY_SIZE; -use ::bitcoin::secp256k1::{self, SecretKey}; use anyhow::{Context, Result}; use bdk::bitcoin::util::bip32::ExtendedPrivKey; use bitcoin::hashes::{sha256, Hash, HashEngine}; +use bitcoin::secp256k1::constants::SECRET_KEY_SIZE; +use bitcoin::secp256k1::{self, SecretKey}; use libp2p::identity; use pem::{encode, Pem}; use rand::prelude::*;