mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-04-27 11:19:18 -04:00
asb: copy file appender log mechanism from cli
This commit is contained in:
parent
a1e32e8b96
commit
ab782cf817
@ -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<Path>,
|
||||
) -> 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);
|
||||
|
@ -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,
|
||||
|
@ -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<Value = Point> {
|
||||
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<Value = ExtendedPrivKey> {
|
||||
prop::array::uniform8(0..255u8).prop_filter_map("invalid secret key generated", |bytes| {
|
||||
|
@ -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::*;
|
||||
|
Loading…
x
Reference in New Issue
Block a user