mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-03-26 07:58:36 -04:00
Toggle json logs using commandline flag.
This commit is contained in:
parent
316f95c65b
commit
fc0cceb180
@ -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.
|
||||
- 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.
|
||||
- Added a new argument to ASB: `--json` or `-j`. If set, log messages will be printed in JSON format.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
13
Cargo.lock
generated
13
Cargo.lock
generated
@ -4289,6 +4289,16 @@ dependencies = [
|
||||
"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]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.2.18"
|
||||
@ -4300,11 +4310,14 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"matchers",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sharded-slab",
|
||||
"thread_local",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
"tracing-serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -61,7 +61,7 @@ torut = { version = "0.1", default-features = false, features = [ "v3", "control
|
||||
tracing = { version = "0.1", features = [ "attributes" ] }
|
||||
tracing-appender = "0.1"
|
||||
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" ] }
|
||||
uuid = { version = "0.8", features = [ "serde", "v4" ] }
|
||||
void = "1"
|
||||
|
@ -10,6 +10,13 @@ use uuid::Uuid;
|
||||
author
|
||||
)]
|
||||
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(
|
||||
long = "config",
|
||||
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 tracing_subscriber::filter::LevelFilter;
|
||||
use tracing_subscriber::fmt::time::ChronoLocal;
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
||||
pub fn init(level: LevelFilter) -> Result<()> {
|
||||
pub fn init(level: LevelFilter, json_format: bool) -> Result<()> {
|
||||
if level == LevelFilter::OFF {
|
||||
return Ok(());
|
||||
}
|
||||
@ -13,12 +14,15 @@ pub fn init(level: LevelFilter) -> Result<()> {
|
||||
.with_env_filter(format!("asb={},swap={}", level, level))
|
||||
.with_writer(std::io::stderr)
|
||||
.with_ansi(is_terminal)
|
||||
.with_timer(ChronoLocal::with_format("%F %T".to_owned()))
|
||||
.with_target(false);
|
||||
|
||||
if !is_terminal {
|
||||
builder.without_time().init();
|
||||
} else {
|
||||
if json_format {
|
||||
builder.json().init();
|
||||
} else if is_terminal {
|
||||
builder.init();
|
||||
} else {
|
||||
builder.without_time().init();
|
||||
}
|
||||
|
||||
tracing::info!(%level, "Initialized tracing");
|
||||
|
@ -45,9 +45,8 @@ const DEFAULT_WALLET_NAME: &str = "asb-wallet";
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
asb::tracing::init(LevelFilter::DEBUG).expect("initialize tracing");
|
||||
|
||||
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 {
|
||||
config_path
|
||||
|
Loading…
x
Reference in New Issue
Block a user