From a81c44f2c8620bad34b89b2a403be5fd70157fef Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 29 Aug 2021 14:31:20 +0200 Subject: [PATCH] refactor(lib): Import tracing macros per-module Instead of one #[macro_use] at the crate root. --- src/body/length.rs | 2 ++ src/client/client.rs | 1 + src/client/conn.rs | 1 + src/client/connect/dns.rs | 1 + src/client/connect/http.rs | 1 + src/client/dispatch.rs | 1 + src/client/pool.rs | 1 + src/client/service.rs | 2 ++ src/lib.rs | 7 ------- src/proto/h1/conn.rs | 6 +++--- src/proto/h1/decode.rs | 1 + src/proto/h1/dispatch.rs | 1 + src/proto/h1/encode.rs | 1 + src/proto/h1/io.rs | 1 + src/proto/h1/role.rs | 14 ++++++++------ src/proto/h2/client.rs | 1 + src/proto/h2/mod.rs | 1 + src/proto/h2/ping.rs | 1 + src/proto/h2/server.rs | 1 + src/server/conn.rs | 2 ++ src/server/shutdown.rs | 1 + src/server/tcp.rs | 1 + src/upgrade.rs | 2 ++ 23 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/body/length.rs b/src/body/length.rs index 633a911f..6e6daa6b 100644 --- a/src/body/length.rs +++ b/src/body/length.rs @@ -50,6 +50,8 @@ impl DecodedLength { /// Checks the `u64` is within the maximum allowed for content-length. #[cfg(any(feature = "http1", feature = "http2"))] pub(crate) fn checked_new(len: u64) -> Result { + use tracing::warn; + if len <= MAX_LEN { Ok(DecodedLength(len)) } else { diff --git a/src/client/client.rs b/src/client/client.rs index e1d5914a..58cd3b1c 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -8,6 +8,7 @@ use futures_util::future::{self, Either, FutureExt as _, TryFutureExt as _}; use http::header::{HeaderValue, HOST}; use http::uri::{Port, Scheme}; use http::{Method, Request, Response, Uri, Version}; +use tracing::{debug, trace, warn}; use super::conn; use super::connect::{self, sealed::Connect, Alpn, Connected, Connection}; diff --git a/src/client/conn.rs b/src/client/conn.rs index c4045203..96913945 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -60,6 +60,7 @@ use httparse::ParserConfig; use pin_project_lite::pin_project; use tokio::io::{AsyncRead, AsyncWrite}; use tower_service::Service; +use tracing::{debug, trace}; use super::dispatch; use crate::body::HttpBody; diff --git a/src/client/connect/dns.rs b/src/client/connect/dns.rs index 08cbb1e8..0036fa2d 100644 --- a/src/client/connect/dns.rs +++ b/src/client/connect/dns.rs @@ -31,6 +31,7 @@ use std::{fmt, io, vec}; use tokio::task::JoinHandle; use tower_service::Service; +use tracing::debug; pub(super) use self::sealed::Resolve; diff --git a/src/client/connect/http.rs b/src/client/connect/http.rs index 0f1a487a..50bb3309 100644 --- a/src/client/connect/http.rs +++ b/src/client/connect/http.rs @@ -14,6 +14,7 @@ use http::uri::{Scheme, Uri}; use pin_project_lite::pin_project; use tokio::net::{TcpSocket, TcpStream}; use tokio::time::Sleep; +use tracing::{debug, trace, warn}; use super::dns::{self, resolve, GaiResolver, Resolve}; use super::{Connected, Connection}; diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 484cb04f..1d2b87eb 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -235,6 +235,7 @@ impl Callback { mut when: impl Future)>> + Unpin, ) { use futures_util::future; + use tracing::trace; let mut cb = Some(self); diff --git a/src/client/pool.rs b/src/client/pool.rs index 9beca9f4..44d4df57 100644 --- a/src/client/pool.rs +++ b/src/client/pool.rs @@ -10,6 +10,7 @@ use std::time::{Duration, Instant}; use futures_channel::oneshot; #[cfg(feature = "runtime")] use tokio::time::{Duration, Instant, Interval}; +use tracing::{debug, trace}; use super::client::Ver; use crate::common::{exec::Exec, task, Future, Pin, Poll, Unpin}; diff --git a/src/client/service.rs b/src/client/service.rs index 4013c5e5..406f61ed 100644 --- a/src/client/service.rs +++ b/src/client/service.rs @@ -6,6 +6,8 @@ use std::error::Error as StdError; use std::future::Future; use std::marker::PhantomData; +use tracing::debug; + use super::conn::{Builder, SendRequest}; use crate::{ body::HttpBody, diff --git a/src/lib.rs b/src/lib.rs index eb7c1730..3c072723 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,13 +58,6 @@ #[doc(hidden)] pub use http; -#[cfg(any( - feature = "http1", - feature = "http2", - all(feature = "client", feature = "tcp") -))] -#[macro_use] -extern crate tracing; #[cfg(all(test, feature = "nightly"))] extern crate test; diff --git a/src/proto/h1/conn.rs b/src/proto/h1/conn.rs index f3eb01ad..c84689e0 100644 --- a/src/proto/h1/conn.rs +++ b/src/proto/h1/conn.rs @@ -7,6 +7,7 @@ use http::header::{HeaderValue, CONNECTION}; use http::{HeaderMap, Method, Version}; use httparse::ParserConfig; use tokio::io::{AsyncRead, AsyncWrite}; +use tracing::{debug, error, trace}; use super::io::Buffered; use super::{Decoder, Encode, EncodedBuf, Encoder, Http1Transaction, ParseContext, Wants}; @@ -538,9 +539,8 @@ where #[cfg(feature = "ffi")] { - self.state.on_informational = head - .extensions - .remove::(); + self.state.on_informational = + head.extensions.remove::(); } Some(encoder) diff --git a/src/proto/h1/decode.rs b/src/proto/h1/decode.rs index 1e6027d9..1e3a38ef 100644 --- a/src/proto/h1/decode.rs +++ b/src/proto/h1/decode.rs @@ -4,6 +4,7 @@ use std::io; use std::usize; use bytes::Bytes; +use tracing::{debug, trace}; use crate::common::{task, Poll}; diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index 51fabc63..d2c1428a 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -3,6 +3,7 @@ use std::error::Error as StdError; use bytes::{Buf, Bytes}; use http::Request; use tokio::io::{AsyncRead, AsyncWrite}; +use tracing::{debug, trace}; use super::{Http1Transaction, Wants}; use crate::body::{Body, DecodedLength, HttpBody}; diff --git a/src/proto/h1/encode.rs b/src/proto/h1/encode.rs index 6a370399..703f4f4f 100644 --- a/src/proto/h1/encode.rs +++ b/src/proto/h1/encode.rs @@ -3,6 +3,7 @@ use std::io::IoSlice; use bytes::buf::{Chain, Take}; use bytes::Buf; +use tracing::trace; use super::io::WriteBuf; diff --git a/src/proto/h1/io.rs b/src/proto/h1/io.rs index 2ff3d5a4..db4eece6 100644 --- a/src/proto/h1/io.rs +++ b/src/proto/h1/io.rs @@ -6,6 +6,7 @@ use std::mem::MaybeUninit; use bytes::{Buf, BufMut, Bytes, BytesMut}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; +use tracing::{debug, trace}; use super::{Http1Transaction, ParseContext, ParsedMessage}; use crate::common::buf::BufList; diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs index 50433b8a..81cb86e8 100644 --- a/src/proto/h1/role.rs +++ b/src/proto/h1/role.rs @@ -8,6 +8,7 @@ use bytes::BytesMut; use http::header::ValueIter; use http::header::{self, Entry, HeaderName, HeaderValue}; use http::{HeaderMap, Method, StatusCode, Version}; +use tracing::{debug, error, trace, trace_span, warn}; use crate::body::DecodedLength; #[cfg(feature = "server")] @@ -117,9 +118,8 @@ impl Http1Transaction for Server { }; { /* SAFETY: it is safe to go from MaybeUninit array to array of MaybeUninit */ - let mut headers: [MaybeUninit>; MAX_HEADERS] = unsafe { - MaybeUninit::uninit().assume_init() - }; + let mut headers: [MaybeUninit>; MAX_HEADERS] = + unsafe { MaybeUninit::uninit().assume_init() }; trace!( "Request.parse([Header; {}], [u8; {}])", headers.len(), @@ -886,9 +886,11 @@ impl Http1Transaction for Client { ); let mut res = httparse::Response::new(&mut []); let bytes = buf.as_ref(); - match ctx.h1_parser_config - .parse_response_with_uninit_headers(&mut res, bytes, &mut headers) - { + match ctx.h1_parser_config.parse_response_with_uninit_headers( + &mut res, + bytes, + &mut headers, + ) { Ok(httparse::Status::Complete(len)) => { trace!("Response.parse Complete({})", len); let status = StatusCode::from_u16(res.code.unwrap())?; diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index 3692a8f2..ae20c851 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -9,6 +9,7 @@ use futures_util::stream::StreamExt as _; use h2::client::{Builder, SendRequest}; use http::{Method, StatusCode}; use tokio::io::{AsyncRead, AsyncWrite}; +use tracing::{debug, trace, warn}; use super::{ping, H2Upgraded, PipeToSendStream, SendBuf}; use crate::body::HttpBody; diff --git a/src/proto/h2/mod.rs b/src/proto/h2/mod.rs index 2b066968..7ad4b48a 100644 --- a/src/proto/h2/mod.rs +++ b/src/proto/h2/mod.rs @@ -8,6 +8,7 @@ use std::io::{self, Cursor, IoSlice}; use std::mem; use std::task::Context; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; +use tracing::{debug, trace, warn}; use crate::body::HttpBody; use crate::common::{task, Future, Pin, Poll}; diff --git a/src/proto/h2/ping.rs b/src/proto/h2/ping.rs index 3ff45cae..1e838649 100644 --- a/src/proto/h2/ping.rs +++ b/src/proto/h2/ping.rs @@ -34,6 +34,7 @@ use std::time::Instant; use h2::{Ping, PingPong}; #[cfg(feature = "runtime")] use tokio::time::{Instant, Sleep}; +use tracing::{debug, trace}; type WindowSize = u32; diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index 1222663d..ad061746 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -9,6 +9,7 @@ use h2::{Reason, RecvStream}; use http::{Method, Request}; use pin_project_lite::pin_project; use tokio::io::{AsyncRead, AsyncWrite}; +use tracing::{debug, trace, warn}; use super::{ping, PipeToSendStream, SendBuf}; use crate::body::HttpBody; diff --git a/src/server/conn.rs b/src/server/conn.rs index 085f8901..07bf3342 100644 --- a/src/server/conn.rs +++ b/src/server/conn.rs @@ -55,6 +55,7 @@ use std::time::Duration; use bytes::Bytes; use pin_project_lite::pin_project; use tokio::io::{AsyncRead, AsyncWrite}; +use tracing::trace; use super::accept::Accept; use crate::body::{Body, HttpBody}; @@ -1037,6 +1038,7 @@ where pub(crate) mod spawn_all { use std::error::Error as StdError; use tokio::io::{AsyncRead, AsyncWrite}; + use tracing::debug; use super::{Connecting, UpgradeableConnection}; use crate::body::{Body, HttpBody}; diff --git a/src/server/shutdown.rs b/src/server/shutdown.rs index 122853ac..8a2ecaf3 100644 --- a/src/server/shutdown.rs +++ b/src/server/shutdown.rs @@ -2,6 +2,7 @@ use std::error::Error as StdError; use pin_project_lite::pin_project; use tokio::io::{AsyncRead, AsyncWrite}; +use tracing::debug; use super::accept::Accept; use super::conn::{SpawnAll, UpgradeableConnection, Watcher}; diff --git a/src/server/tcp.rs b/src/server/tcp.rs index 792e0034..013bdaea 100644 --- a/src/server/tcp.rs +++ b/src/server/tcp.rs @@ -5,6 +5,7 @@ use std::time::Duration; use tokio::net::TcpListener; use tokio::time::Sleep; +use tracing::{debug, error, trace}; use crate::common::{task, Future, Pin, Poll}; diff --git a/src/upgrade.rs b/src/upgrade.rs index efab10a6..be4e4822 100644 --- a/src/upgrade.rs +++ b/src/upgrade.rs @@ -14,6 +14,8 @@ use std::marker::Unpin; use bytes::Bytes; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use tokio::sync::oneshot; +#[cfg(any(feature = "http1", feature = "http2"))] +use tracing::trace; use crate::common::io::Rewind; use crate::common::{task, Future, Pin, Poll};