diff options
author | Alex Auvolat <alex@adnab.me> | 2020-12-04 13:58:34 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-12-04 13:58:34 +0100 |
commit | b63179c699e0569d45826bccb4b9f2f1bc53c30e (patch) | |
tree | 7472ccda59d37531edbb3ffeff207edef51ee09d /examples | |
parent | 56c524bbea64a85d7ced56406b0855041783845f (diff) | |
download | netapp-b63179c699e0569d45826bccb4b9f2f1bc53c30e.tar.gz netapp-b63179c699e0569d45826bccb4b9f2f1bc53c30e.zip |
Logging
Diffstat (limited to 'examples')
-rw-r--r-- | examples/basalt.rs | 28 | ||||
-rw-r--r-- | examples/fullmesh.rs | 12 |
2 files changed, 31 insertions, 9 deletions
diff --git a/examples/basalt.rs b/examples/basalt.rs index e09f627..141069a 100644 --- a/examples/basalt.rs +++ b/examples/basalt.rs @@ -1,8 +1,9 @@ use std::net::SocketAddr; use std::sync::Arc; use std::time::Duration; +use std::io::Write; -use log::{info, warn}; +use log::{debug, info, warn}; use structopt::StructOpt; use serde::{Deserialize, Serialize}; @@ -48,7 +49,18 @@ pub struct Opt { #[tokio::main] async fn main() { - pretty_env_logger::init(); + env_logger::Builder::new() + .parse_env("RUST_LOG") + .format(|buf, record| { + writeln!(buf, + "{} {} {}", + chrono::Local::now().format("%s%.6f"), + record.level(), + record.args() + ) + }) + .init(); + let opt = Opt::from_args(); @@ -56,7 +68,7 @@ async fn main() { Some(k) => auth::Key::from_slice(&hex::decode(k).unwrap()).unwrap(), None => auth::gen_key(), }; - info!("Network key: {}", hex::encode(&netid)); + info!("KYEV NK {}", hex::encode(&netid)); let privkey = match &opt.private_key { Some(k) => ed25519::SecretKey::from_slice(&hex::decode(k).unwrap()).unwrap(), @@ -66,8 +78,8 @@ async fn main() { } }; - info!("Node private key: {}", hex::encode(&privkey)); - info!("Node public key: {}", hex::encode(&privkey.public_key())); + info!("KYEV SK {}", hex::encode(&privkey)); + info!("KYEV PK {}", hex::encode(&privkey.public_key())); let listen_addr = opt.listen_addr.parse().unwrap(); let netapp = NetApp::new(listen_addr, netid, privkey); @@ -93,7 +105,7 @@ async fn main() { netapp.add_msg_handler::<ExampleMessage, _, _>( |_from: ed25519::PublicKey, msg: ExampleMessage| { - info!("Got example message: {:?}, sending example response", msg); + debug!("Got example message: {:?}, sending example response", msg); async { ExampleResponse{example_field: false} } @@ -115,14 +127,14 @@ async fn sampling_loop(netapp: Arc<NetApp>, basalt: Arc<Basalt>) { let peers = basalt.sample(10); for p in peers { - info!("Sampled: {}", hex::encode(p)); + info!("KYEV S {}", hex::encode(p)); let netapp2 = netapp.clone(); tokio::spawn(async move { match netapp2.request(&p, ExampleMessage{ example_field: 42, }, PRIO_NORMAL).await { - Ok(resp) => info!("Got example response: {:?}", resp), + Ok(resp) => debug!("Got example response: {:?}", resp), Err(e) => warn!("Error with example request: {}", e), } }); diff --git a/examples/fullmesh.rs b/examples/fullmesh.rs index af315fb..a61ab3d 100644 --- a/examples/fullmesh.rs +++ b/examples/fullmesh.rs @@ -28,7 +28,17 @@ pub struct Opt { #[tokio::main] async fn main() { - pretty_env_logger::init(); + env_logger::Builder::new() + .parse_env("RUST_LOG") + .format(|buf, record| { + writeln!(buf, + "{} {} {}", + chrono::Local::now().format("%s%.6f"), + record.level(), + record.args() + ) + }) + .init(); let opt = Opt::from_args(); |