mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-22 08:21:27 -04:00
Toggle json logs using commandline flag.
This commit is contained in:
parent
316f95c65b
commit
fc0cceb180
6 changed files with 31 additions and 7 deletions
|
@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
When started with `--resume-only` the ASB does not accept new, incoming swap requests but only finishes swaps that are resumed upon startup.
|
When started with `--resume-only` the ASB does not accept new, incoming swap requests but only finishes swaps that are resumed upon startup.
|
||||||
- A minimum accepted Bitcoin amount for the ASB similar to the maximum amount already present.
|
- A minimum accepted Bitcoin amount for the ASB similar to the maximum amount already present.
|
||||||
For the CLI the minimum amount is enforced by waiting until at least the minimum is available as max-giveable amount.
|
For the CLI the minimum amount is enforced by waiting until at least the minimum is available as max-giveable amount.
|
||||||
|
- Added a new argument to ASB: `--json` or `-j`. If set, log messages will be printed in JSON format.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -4289,6 +4289,16 @@ dependencies = [
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-serde"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"tracing-core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-subscriber"
|
name = "tracing-subscriber"
|
||||||
version = "0.2.18"
|
version = "0.2.18"
|
||||||
|
@ -4300,11 +4310,14 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"matchers",
|
"matchers",
|
||||||
"regex",
|
"regex",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"sharded-slab",
|
"sharded-slab",
|
||||||
"thread_local",
|
"thread_local",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
"tracing-log",
|
"tracing-log",
|
||||||
|
"tracing-serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -61,7 +61,7 @@ torut = { version = "0.1", default-features = false, features = [ "v3", "control
|
||||||
tracing = { version = "0.1", features = [ "attributes" ] }
|
tracing = { version = "0.1", features = [ "attributes" ] }
|
||||||
tracing-appender = "0.1"
|
tracing-appender = "0.1"
|
||||||
tracing-futures = { version = "0.2", features = [ "std-future", "futures-03" ] }
|
tracing-futures = { version = "0.2", features = [ "std-future", "futures-03" ] }
|
||||||
tracing-subscriber = { version = "0.2", default-features = false, features = [ "fmt", "ansi", "env-filter", "chrono", "tracing-log" ] }
|
tracing-subscriber = { version = "0.2", default-features = false, features = [ "fmt", "ansi", "env-filter", "chrono", "tracing-log", "json" ] }
|
||||||
url = { version = "2", features = [ "serde" ] }
|
url = { version = "2", features = [ "serde" ] }
|
||||||
uuid = { version = "0.8", features = [ "serde", "v4" ] }
|
uuid = { version = "0.8", features = [ "serde", "v4" ] }
|
||||||
void = "1"
|
void = "1"
|
||||||
|
|
|
@ -10,6 +10,13 @@ use uuid::Uuid;
|
||||||
author
|
author
|
||||||
)]
|
)]
|
||||||
pub struct Arguments {
|
pub struct Arguments {
|
||||||
|
#[structopt(
|
||||||
|
short,
|
||||||
|
long = "json",
|
||||||
|
help = "Changes the log messages to json vs plain-text. If you run ASB as a service, it is recommended to set this to true to simplify log analyses."
|
||||||
|
)]
|
||||||
|
pub json: bool,
|
||||||
|
|
||||||
#[structopt(
|
#[structopt(
|
||||||
long = "config",
|
long = "config",
|
||||||
help = "Provide a custom path to the configuration file. The configuration file must be a toml file.",
|
help = "Provide a custom path to the configuration file. The configuration file must be a toml file.",
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tracing_subscriber::filter::LevelFilter;
|
use tracing_subscriber::filter::LevelFilter;
|
||||||
|
use tracing_subscriber::fmt::time::ChronoLocal;
|
||||||
use tracing_subscriber::FmtSubscriber;
|
use tracing_subscriber::FmtSubscriber;
|
||||||
|
|
||||||
pub fn init(level: LevelFilter) -> Result<()> {
|
pub fn init(level: LevelFilter, json_format: bool) -> Result<()> {
|
||||||
if level == LevelFilter::OFF {
|
if level == LevelFilter::OFF {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -13,12 +14,15 @@ pub fn init(level: LevelFilter) -> Result<()> {
|
||||||
.with_env_filter(format!("asb={},swap={}", level, level))
|
.with_env_filter(format!("asb={},swap={}", level, level))
|
||||||
.with_writer(std::io::stderr)
|
.with_writer(std::io::stderr)
|
||||||
.with_ansi(is_terminal)
|
.with_ansi(is_terminal)
|
||||||
|
.with_timer(ChronoLocal::with_format("%F %T".to_owned()))
|
||||||
.with_target(false);
|
.with_target(false);
|
||||||
|
|
||||||
if !is_terminal {
|
if json_format {
|
||||||
builder.without_time().init();
|
builder.json().init();
|
||||||
} else {
|
} else if is_terminal {
|
||||||
builder.init();
|
builder.init();
|
||||||
|
} else {
|
||||||
|
builder.without_time().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
tracing::info!(%level, "Initialized tracing");
|
tracing::info!(%level, "Initialized tracing");
|
||||||
|
|
|
@ -45,9 +45,8 @@ const DEFAULT_WALLET_NAME: &str = "asb-wallet";
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
asb::tracing::init(LevelFilter::DEBUG).expect("initialize tracing");
|
|
||||||
|
|
||||||
let opt = Arguments::from_args();
|
let opt = Arguments::from_args();
|
||||||
|
asb::tracing::init(LevelFilter::DEBUG, opt.json).expect("initialize tracing");
|
||||||
|
|
||||||
let config_path = if let Some(config_path) = opt.config {
|
let config_path = if let Some(config_path) = opt.config {
|
||||||
config_path
|
config_path
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue