refactor(logging): move from log to tracing

This commit is contained in:
Paolo Barbolini
2020-08-28 12:19:35 +02:00
committed by Alexis Mousset
parent 41d68616e0
commit 542ea4ffd2
11 changed files with 35 additions and 35 deletions

View File

@@ -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"] }

View File

@@ -1,7 +1,7 @@
use lettre::{Message, SmtpTransport, Transport};
fn main() {
env_logger::init();
tracing_subscriber::fmt::init();
let email = Message::builder()
.from("NoBody <nobody@domain.tld>".parse().unwrap())

View File

@@ -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 <nobody@domain.tld>".parse().unwrap())
.reply_to("Yuin <yuin@domain.tld>".parse().unwrap())

View File

@@ -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 <nobody@domain.tld>".parse().unwrap())
.reply_to("Yuin <yuin@domain.tld>".parse().unwrap())

View File

@@ -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 <nobody@domain.tld>".parse().unwrap())
.reply_to("Yuin <yuin@domain.tld>".parse().unwrap())

View File

@@ -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 <nobody@domain.tld>".parse().unwrap())
.reply_to("Yuin <yuin@domain.tld>".parse().unwrap())

View File

@@ -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

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -74,7 +74,7 @@ impl ClientCodec {
/// Returns the string replacing all the CRLF with "\<CRLF\>"
/// Used for debug displays
#[cfg(feature = "log")]
#[cfg(feature = "tracing")]
pub(super) fn escape_crlf(string: &str) -> String {
string.replace("\r\n", "<CRLF>")
}

View File

@@ -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()))?);