From 7625c364a6ed22e504c86a01c44fe37dd40d08be Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Tue, 12 Dec 2017 14:02:45 +0100 Subject: [PATCH] Added logging support via the log crate. --- Cargo.toml | 1 + src/client/conn.rs | 4 +++- src/client/server/mod.rs | 2 ++ src/lib.rs | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5c6a7db..fd86cda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ chrono = "0.4" encoding = "0.2" error-chain = "0.10" futures = "0.1" +log = "0.3" native-tls = "0.1" serde = "1.0" serde_derive = "1.0" diff --git a/src/client/conn.rs b/src/client/conn.rs index bb2848d..cf8d5ab 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -109,6 +109,7 @@ impl Connection { Ok(ConnectionFuture::Mock(config)) } else if config.use_ssl() { let domain = format!("{}", config.server()); + info!("Connecting via SSL to {}.", domain); let mut builder = TlsConnector::builder()?; if let Some(cert_path) = config.cert_path() { let mut file = File::open(cert_path)?; @@ -116,7 +117,7 @@ impl Connection { file.read_to_end(&mut cert_data)?; let cert = Certificate::from_der(&cert_data)?; builder.add_root_certificate(cert)?; - println!("Added {} to trusted certificates.", cert_path); + info!("Added {} to trusted certificates.", cert_path); } let connector = builder.build()?; let stream = Box::new(TcpStream::connect(&config.socket_addr()?, handle) @@ -132,6 +133,7 @@ impl Connection { )); Ok(ConnectionFuture::Secured(config, stream)) } else { + info!("Connecting to {}.", config.server()); Ok(ConnectionFuture::Unsecured( config, TcpStream::connect(&config.socket_addr()?, handle), diff --git a/src/client/server/mod.rs b/src/client/server/mod.rs index 41d2d39..deb6273 100644 --- a/src/client/server/mod.rs +++ b/src/client/server/mod.rs @@ -333,6 +333,7 @@ impl ServerState { /// Handles sent messages internally for basic client functionality. fn handle_sent_message(&self, msg: &Message) -> error::Result<()> { + trace!("[SENT] {}", msg.to_string()); match msg.command { PART(ref chan, _) => { let _ = self.chanlists.lock().unwrap().remove(chan); @@ -344,6 +345,7 @@ impl ServerState { /// Handles received messages internally for basic client functionality. fn handle_message(&self, msg: &Message) -> error::Result<()> { + trace!("[RECV] {}", msg.to_string()); match msg.command { JOIN(ref chan, _, _) => self.handle_join(msg.source_nickname().unwrap_or(""), chan), PART(ref chan, _) => self.handle_part(msg.source_nickname().unwrap_or(""), chan), diff --git a/src/lib.rs b/src/lib.rs index 823ab96..a384081 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,8 @@ extern crate error_chain; extern crate encoding; #[macro_use] extern crate futures; +#[macro_use] +extern crate log; extern crate native_tls; extern crate serde; #[macro_use]