conditionally disable verbose logging

pull/92/head
qiujiangkun 4 years ago
parent 83395f3d7c
commit a5d69de82c
  1. 1
      Cargo.toml
  2. 8
      src/compat.rs
  3. 3
      src/lib.rs

@ -23,6 +23,7 @@ tokio-native-tls = ["tokio-runtime", "real-tokio-native-tls", "real-native-tls",
tokio-rustls-webpki-roots = ["tokio-runtime", "real-tokio-rustls", "webpki-roots", "tungstenite/rustls-tls"] tokio-rustls-webpki-roots = ["tokio-runtime", "real-tokio-rustls", "webpki-roots", "tungstenite/rustls-tls"]
tokio-rustls-native-certs = ["tokio-runtime", "real-tokio-rustls", "rustls-native-certs", "tungstenite/rustls-tls"] tokio-rustls-native-certs = ["tokio-runtime", "real-tokio-rustls", "rustls-native-certs", "tungstenite/rustls-tls"]
tokio-openssl = ["tokio-runtime", "real-tokio-openssl", "openssl"] tokio-openssl = ["tokio-runtime", "real-tokio-openssl", "openssl"]
no-verbose-logging = []
[package.metadata.docs.rs] [package.metadata.docs.rs]
features = ["async-std-runtime", "tokio-runtime", "gio-runtime", "async-tls", "async-native-tls", "tokio-native-tls"] features = ["async-std-runtime", "tokio-runtime", "gio-runtime", "async-tls", "async-native-tls", "tokio-native-tls"]

@ -121,6 +121,7 @@ where
where where
F: FnOnce(&mut Context<'_>, Pin<&mut S>) -> Poll<std::io::Result<R>>, F: FnOnce(&mut Context<'_>, Pin<&mut S>) -> Poll<std::io::Result<R>>,
{ {
#[cfg(not(feature = "no-verbose-logging"))]
trace!("{}:{} AllowStd.with_context", file!(), line!()); trace!("{}:{} AllowStd.with_context", file!(), line!());
let waker = match kind { let waker = match kind {
ContextWaker::Read => task::waker_ref(&self.read_waker_proxy), ContextWaker::Read => task::waker_ref(&self.read_waker_proxy),
@ -144,8 +145,10 @@ where
S: AsyncRead + Unpin, S: AsyncRead + Unpin,
{ {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> { fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
#[cfg(not(feature = "no-verbose-logging"))]
trace!("{}:{} Read.read", file!(), line!()); trace!("{}:{} Read.read", file!(), line!());
match self.with_context(ContextWaker::Read, |ctx, stream| { match self.with_context(ContextWaker::Read, |ctx, stream| {
#[cfg(not(feature = "no-verbose-logging"))]
trace!( trace!(
"{}:{} Read.with_context read -> poll_read", "{}:{} Read.with_context read -> poll_read",
file!(), file!(),
@ -164,8 +167,10 @@ where
S: AsyncWrite + Unpin, S: AsyncWrite + Unpin,
{ {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
#[cfg(not(feature = "no-verbose-logging"))]
trace!("{}:{} Write.write", file!(), line!()); trace!("{}:{} Write.write", file!(), line!());
match self.with_context(ContextWaker::Write, |ctx, stream| { match self.with_context(ContextWaker::Write, |ctx, stream| {
#[cfg(not(feature = "no-verbose-logging"))]
trace!( trace!(
"{}:{} Write.with_context write -> poll_write", "{}:{} Write.with_context write -> poll_write",
file!(), file!(),
@ -179,8 +184,10 @@ where
} }
fn flush(&mut self) -> std::io::Result<()> { fn flush(&mut self) -> std::io::Result<()> {
#[cfg(not(feature = "no-verbose-logging"))]
trace!("{}:{} Write.flush", file!(), line!()); trace!("{}:{} Write.flush", file!(), line!());
match self.with_context(ContextWaker::Write, |ctx, stream| { match self.with_context(ContextWaker::Write, |ctx, stream| {
#[cfg(not(feature = "no-verbose-logging"))]
trace!( trace!(
"{}:{} Write.with_context flush -> poll_flush", "{}:{} Write.with_context flush -> poll_flush",
file!(), file!(),
@ -198,6 +205,7 @@ pub(crate) fn cvt<T>(r: Result<T, WsError>) -> Poll<Result<T, WsError>> {
match r { match r {
Ok(v) => Poll::Ready(Ok(v)), Ok(v) => Poll::Ready(Ok(v)),
Err(WsError::Io(ref e)) if e.kind() == std::io::ErrorKind::WouldBlock => { Err(WsError::Io(ref e)) if e.kind() == std::io::ErrorKind::WouldBlock => {
#[cfg(not(feature = "no-verbose-logging"))]
trace!("WouldBlock"); trace!("WouldBlock");
Poll::Pending Poll::Pending
} }

@ -260,6 +260,7 @@ impl<S> WebSocketStream<S> {
F: FnOnce(&mut WebSocket<AllowStd<S>>) -> R, F: FnOnce(&mut WebSocket<AllowStd<S>>) -> R,
AllowStd<S>: Read + Write, AllowStd<S>: Read + Write,
{ {
#[cfg(not(feature = "no-verbose-logging"))]
trace!("{}:{} WebSocketStream.with_context", file!(), line!()); trace!("{}:{} WebSocketStream.with_context", file!(), line!());
if let Some((kind, ctx)) = ctx { if let Some((kind, ctx)) = ctx {
self.inner.get_mut().set_waker(kind, &ctx.waker()); self.inner.get_mut().set_waker(kind, &ctx.waker());
@ -305,8 +306,10 @@ where
type Item = Result<Message, WsError>; type Item = Result<Message, WsError>;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
#[cfg(not(feature = "no-verbose-logging"))]
trace!("{}:{} Stream.poll_next", file!(), line!()); trace!("{}:{} Stream.poll_next", file!(), line!());
match futures_util::ready!(self.with_context(Some((ContextWaker::Read, cx)), |s| { match futures_util::ready!(self.with_context(Some((ContextWaker::Read, cx)), |s| {
#[cfg(not(feature = "no-verbose-logging"))]
trace!( trace!(
"{}:{} Stream.with_context poll_next -> read_message()", "{}:{} Stream.with_context poll_next -> read_message()",
file!(), file!(),

Loading…
Cancel
Save