diff --git a/Cargo.toml b/Cargo.toml index d1a1218..19baf99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ base64 = { version = "0.12", optional = true } hostname = { version = "0.3", optional = true } hyperx = { version = "1", optional = true, features = ["headers"] } idna = "0.2" -log = { version = "0.4", optional = true } +tracing = { version = "0.1.16", optional = true } mime = { version = "0.3", optional = true } native-tls = { version = "0.2", optional = true } nom = { version = "5", optional = true } @@ -47,7 +47,7 @@ webpki-roots = { version = "0.20", optional = true } [dev-dependencies] criterion = "0.3" -env_logger = "0.7" +tracing-subscriber = "0.2.10" glob = "0.3" walkdir = "2" tokio02_crate = { package = "tokio", version = "0.2.7", features = ["macros", "rt-threaded"] } diff --git a/examples/smtp.rs b/examples/smtp.rs index f2b8b31..e865e05 100644 --- a/examples/smtp.rs +++ b/examples/smtp.rs @@ -1,7 +1,7 @@ use lettre::{Message, SmtpTransport, Transport}; fn main() { - env_logger::init(); + tracing_subscriber::fmt::init(); let email = Message::builder() .from("NoBody ".parse().unwrap()) diff --git a/examples/smtp_starttls.rs b/examples/smtp_starttls.rs index b4bd71a..3e03f52 100644 --- a/examples/smtp_starttls.rs +++ b/examples/smtp_starttls.rs @@ -2,6 +2,8 @@ use lettre::transport::smtp::authentication::Credentials; use lettre::{Message, SmtpTransport, Transport}; fn main() { + tracing_subscriber::fmt::init(); + let email = Message::builder() .from("NoBody ".parse().unwrap()) .reply_to("Yuin ".parse().unwrap()) diff --git a/examples/smtp_tls.rs b/examples/smtp_tls.rs index f5dee63..ee87bf4 100644 --- a/examples/smtp_tls.rs +++ b/examples/smtp_tls.rs @@ -2,6 +2,8 @@ use lettre::transport::smtp::authentication::Credentials; use lettre::{Message, SmtpTransport, Transport}; fn main() { + tracing_subscriber::fmt::init(); + let email = Message::builder() .from("NoBody ".parse().unwrap()) .reply_to("Yuin ".parse().unwrap()) diff --git a/examples/tokio02_smtp_starttls.rs b/examples/tokio02_smtp_starttls.rs index 2f9663e..04f6f87 100644 --- a/examples/tokio02_smtp_starttls.rs +++ b/examples/tokio02_smtp_starttls.rs @@ -8,6 +8,8 @@ use lettre::{AsyncSmtpTransport, Message, Tokio02Connector, Tokio02Transport}; #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + let email = Message::builder() .from("NoBody ".parse().unwrap()) .reply_to("Yuin ".parse().unwrap()) diff --git a/examples/tokio02_smtp_tls.rs b/examples/tokio02_smtp_tls.rs index 979b125..791e848 100644 --- a/examples/tokio02_smtp_tls.rs +++ b/examples/tokio02_smtp_tls.rs @@ -8,6 +8,8 @@ use lettre::{AsyncSmtpTransport, Message, Tokio02Connector, Tokio02Transport}; #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + let email = Message::builder() .from("NoBody ".parse().unwrap()) .reply_to("Yuin ".parse().unwrap()) diff --git a/src/lib.rs b/src/lib.rs index fbb3651..ffbf098 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ //! * **rustls-tls**: TLS support with the `rustls` crate //! * **native-tls**: TLS support with the `native-tls` crate //! * **r2d2**: Connection pool for SMTP transport -//! * **log**: Logging using the `log` crate +//! * **tracing**: Logging using the `tracing` crate //! * **serde**: Serialization/Deserialization of entities //! * **hostname**: Ability to try to use actual hostname in SMTP transaction diff --git a/src/transport/smtp/client/async_connection.rs b/src/transport/smtp/client/async_connection.rs index 43d176b..cdfd970 100644 --- a/src/transport/smtp/client/async_connection.rs +++ b/src/transport/smtp/client/async_connection.rs @@ -2,9 +2,6 @@ use std::{fmt::Display, io}; use futures_util::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; -#[cfg(feature = "log")] -use log::debug; - use super::{AsyncNetworkStream, ClientCodec, TlsParameters}; use crate::{ transport::smtp::{ @@ -17,7 +14,7 @@ use crate::{ Envelope, }; -#[cfg(feature = "log")] +#[cfg(feature = "tracing")] use super::escape_crlf; macro_rules! try_smtp ( @@ -79,8 +76,8 @@ impl AsyncSmtpConnection { conn.ehlo(hello_name).await?; // Print server information - #[cfg(feature = "log")] - debug!("server {}", conn.server_info); + #[cfg(feature = "tracing")] + tracing::debug!("server {}", conn.server_info); Ok(conn) } @@ -133,8 +130,8 @@ impl AsyncSmtpConnection { self.stream.get_mut().upgrade_tls(tls_parameters).await, self ); - #[cfg(feature = "log")] - debug!("connection encrypted"); + #[cfg(feature = "tracing")] + tracing::debug!("connection encrypted"); // Send EHLO again try_smtp!(self.ehlo(hello_name).await, self); Ok(()) @@ -237,8 +234,8 @@ impl AsyncSmtpConnection { self.stream.get_mut().write_all(string).await?; self.stream.get_mut().flush().await?; - #[cfg(feature = "log")] - debug!("Wrote: {}", escape_crlf(&String::from_utf8_lossy(string))); + #[cfg(feature = "tracing")] + tracing::debug!("Wrote: {}", escape_crlf(&String::from_utf8_lossy(string))); Ok(()) } @@ -247,8 +244,8 @@ impl AsyncSmtpConnection { let mut buffer = String::with_capacity(100); while self.stream.read_line(&mut buffer).await? > 0 { - #[cfg(feature = "log")] - debug!("<< {}", escape_crlf(&buffer)); + #[cfg(feature = "tracing")] + tracing::debug!("<< {}", escape_crlf(&buffer)); match parse_response(&buffer) { Ok((_remaining, response)) => { if response.is_positive() { diff --git a/src/transport/smtp/client/connection.rs b/src/transport/smtp/client/connection.rs index d5c3268..12bd63a 100644 --- a/src/transport/smtp/client/connection.rs +++ b/src/transport/smtp/client/connection.rs @@ -5,9 +5,6 @@ use std::{ time::Duration, }; -#[cfg(feature = "log")] -use log::debug; - use super::{ClientCodec, NetworkStream, TlsParameters}; use crate::{ transport::smtp::{ @@ -20,7 +17,7 @@ use crate::{ Envelope, }; -#[cfg(feature = "log")] +#[cfg(feature = "tracing")] use super::escape_crlf; macro_rules! try_smtp ( @@ -76,8 +73,8 @@ impl SmtpConnection { conn.ehlo(hello_name)?; // Print server information - #[cfg(feature = "log")] - debug!("server {}", conn.server_info); + #[cfg(feature = "tracing")] + tracing::debug!("server {}", conn.server_info); Ok(conn) } @@ -125,8 +122,8 @@ impl SmtpConnection { { try_smtp!(self.command(Starttls), self); try_smtp!(self.stream.get_mut().upgrade_tls(tls_parameters), self); - #[cfg(feature = "log")] - debug!("connection encrypted"); + #[cfg(feature = "tracing")] + tracing::debug!("connection encrypted"); // Send EHLO again try_smtp!(self.ehlo(hello_name), self); Ok(()) @@ -237,8 +234,8 @@ impl SmtpConnection { self.stream.get_mut().write_all(string)?; self.stream.get_mut().flush()?; - #[cfg(feature = "log")] - debug!("Wrote: {}", escape_crlf(&String::from_utf8_lossy(string))); + #[cfg(feature = "tracing")] + tracing::debug!("Wrote: {}", escape_crlf(&String::from_utf8_lossy(string))); Ok(()) } @@ -247,8 +244,8 @@ impl SmtpConnection { let mut buffer = String::with_capacity(100); while self.stream.read_line(&mut buffer)? > 0 { - #[cfg(feature = "log")] - debug!("<< {}", escape_crlf(&buffer)); + #[cfg(feature = "tracing")] + tracing::debug!("<< {}", escape_crlf(&buffer)); match parse_response(&buffer) { Ok((_remaining, response)) => { if response.is_positive() { diff --git a/src/transport/smtp/client/mod.rs b/src/transport/smtp/client/mod.rs index b80e8c0..cba13cf 100644 --- a/src/transport/smtp/client/mod.rs +++ b/src/transport/smtp/client/mod.rs @@ -74,7 +74,7 @@ impl ClientCodec { /// Returns the string replacing all the CRLF with "\" /// Used for debug displays -#[cfg(feature = "log")] +#[cfg(feature = "tracing")] pub(super) fn escape_crlf(string: &str) -> String { string.replace("\r\n", "") } diff --git a/src/transport/smtp/commands.rs b/src/transport/smtp/commands.rs index f710afe..abc9575 100644 --- a/src/transport/smtp/commands.rs +++ b/src/transport/smtp/commands.rs @@ -9,8 +9,6 @@ use crate::{ }, Address, }; -#[cfg(feature = "log")] -use log::debug; use std::{ convert::AsRef, fmt::{self, Display, Formatter}, @@ -275,12 +273,12 @@ impl Auth { let encoded_challenge = response .first_word() .ok_or(Error::ResponseParsing("Could not read auth challenge"))?; - #[cfg(feature = "log")] - debug!("auth encoded challenge: {}", encoded_challenge); + #[cfg(feature = "tracing")] + tracing::debug!("auth encoded challenge: {}", encoded_challenge); let decoded_challenge = String::from_utf8(base64::decode(&encoded_challenge)?)?; - #[cfg(feature = "log")] - debug!("auth decoded challenge: {}", decoded_challenge); + #[cfg(feature = "tracing")] + tracing::debug!("auth decoded challenge: {}", decoded_challenge); let response = Some(mechanism.response(&credentials, Some(decoded_challenge.as_ref()))?);