Skip to content

Commit

Permalink
Merge #32: Setup log levels at environment
Browse files Browse the repository at this point in the history
10ee94d Add more logging informations (mojoX911)
7920f1f Fixed Logging initialisation (mojoX911)
d1ffc26 Adds env_logger (mojoX911)

Tree-SHA512: 867b8b8f94dc43e2ecb23d26a34f0bdeab722e938620829757fc3e7bcc804e593fc3d5401f6b9628e5f5eae0b26bcb6d1039cda6b7a9e5ee98313c9be0650199
  • Loading branch information
chris-belcher committed Oct 6, 2021
2 parents c13662f + 10ee94d commit 5f6283e
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 73 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "0.3", features = ["full"] }
log = "^0.4"
env_logger = "0.7"
futures = "0.3"
rand = "0.7.3"
itertools = "0.9.0"
Expand Down
19 changes: 19 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use dirs::home_dir;
use std::io;
use std::iter::repeat;
use std::path::PathBuf;
use std::sync::Once;
use std::sync::{Arc, RwLock};

use bitcoin::hashes::{hash160::Hash as Hash160, hex::ToHex};
Expand Down Expand Up @@ -439,7 +440,23 @@ enum Subcommand {
},
}

static INIT: Once = Once::new();

/// Setup function that will only run once, even if called multiple times.
fn setup_logger() {
INIT.call_once(|| {
env_logger::Builder::from_env(
env_logger::Env::default()
.default_filter_or("teleport=info")
.default_write_style_or("always"),
)
.init();
});
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
setup_logger();

let args = ArgsWithWalletFile::from_args();

match args.subcommand {
Expand Down Expand Up @@ -538,6 +555,8 @@ mod test {
// wallet name `teleport` loaded and have enough balance to execute transactions.
#[tokio::test]
async fn test_standard_coin_swap() {
setup_logger();

let rpc = get_bitcoin_rpc().unwrap();

// unlock all utxos to avoid "insufficient fund" error
Expand Down
Loading

0 comments on commit 5f6283e

Please sign in to comment.