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-native-certs = ["tokio-runtime", "real-tokio-rustls", "rustls-native-certs", "tungstenite/rustls-tls"]
tokio-openssl = ["tokio-runtime", "real-tokio-openssl", "openssl"]
no-verbose-logging = []
[package.metadata.docs.rs]
features = ["async-std-runtime", "tokio-runtime", "gio-runtime", "async-tls", "async-native-tls", "tokio-native-tls"]

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

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

Loading…
Cancel
Save