Skip to content

Commit 45177ca

Browse files
committed
Add logger to the project
1 parent 8eccb4d commit 45177ca

File tree

3 files changed

+104
-3
lines changed

3 files changed

+104
-3
lines changed

Cargo.lock

+97
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ hmac-sha512 = "1.1.4"
1515
libp2p = { version = "0.51.3", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] }
1616
log = "0.4.17"
1717
multiaddr = "0.17.1"
18+
pretty_env_logger = "0.4.0"

src/main.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ use libp2p::swarm::keep_alive::Behaviour;
88
use libp2p::swarm::SwarmEvent;
99
use libp2p::{identity, noise, swarm::SwarmBuilder, tcp, yamux};
1010
use libp2p::{PeerId, Transport};
11+
use log::info;
1112

1213
#[async_std::main]
1314
async fn main() -> Result<(), Box<dyn Error>> {
15+
pretty_env_logger::init();
16+
1417
let local_key = identity::Keypair::generate_ed25519();
1518
let local_peer_id = PeerId::from(local_key.public());
16-
println!("Local peer id: {local_peer_id:?}");
19+
info!("Local peer id: {local_peer_id:?}");
1720

1821
let transport = tcp::async_io::Transport::default()
1922
.upgrade(Version::V1Lazy)
@@ -33,8 +36,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
3336

3437
loop {
3538
match swarm.select_next_some().await {
36-
SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {address:?}"),
37-
SwarmEvent::Behaviour(event) => println!("{event:?}"),
39+
SwarmEvent::NewListenAddr { address, .. } => info!("Listening on {address:?}"),
40+
SwarmEvent::Behaviour(event) => info!("{event:?}"),
3841
_ => {}
3942
}
4043
}

0 commit comments

Comments
 (0)