diff --git a/Cargo.toml b/Cargo.toml index 041dc222b..bb84d24ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ include = [ # For documentation of features see the `mio::features` module. [features] # By default Mio only provides a shell implementation. -default = [] +default = ["log"] # Enables the `Poll` and `Registry` types. os-poll = [] @@ -50,7 +50,7 @@ pipe = ["os-ext"] # Replaced with "os-ext" feature. os-util = ["os-ext"]# Replaced with "os-ext" feature. [dependencies] -log = "0.4.8" +log = { version = "0.4.8", optional = true } [target.'cfg(unix)'.dependencies] libc = "0.2.86" diff --git a/src/macros.rs b/src/macros.rs index f97f90911..3d42bd20a 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -68,3 +68,27 @@ macro_rules! cfg_any_os_ext { )* } } + +macro_rules! trace { + ($($t:tt)*) => { + #[cfg(feature = "log")] + log::trace!($($t)*) + } +} + +macro_rules! error { + ($($t:tt)*) => { + #[cfg(feature = "log")] + { + log::error!($($t)*) + } + + // Silence warnings + #[cfg(not(feature = "log"))] + { + if false { + format!($($t)*); + } + } + } +} diff --git a/src/poll.rs b/src/poll.rs index a6f4ab0b5..09124779b 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -1,5 +1,4 @@ use crate::{event, sys, Events, Interest, Token}; -use log::trace; #[cfg(unix)] use std::os::unix::io::{AsRawFd, RawFd}; use std::time::Duration; diff --git a/src/sys/unix/selector/epoll.rs b/src/sys/unix/selector/epoll.rs index 38667d66c..e3af341a4 100644 --- a/src/sys/unix/selector/epoll.rs +++ b/src/sys/unix/selector/epoll.rs @@ -1,7 +1,6 @@ use crate::{Interest, Token}; use libc::{EPOLLET, EPOLLIN, EPOLLOUT, EPOLLRDHUP}; -use log::error; use std::os::unix::io::{AsRawFd, RawFd}; #[cfg(debug_assertions)] use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; diff --git a/src/sys/unix/selector/kqueue.rs b/src/sys/unix/selector/kqueue.rs index b7a01a51c..4937d57ac 100644 --- a/src/sys/unix/selector/kqueue.rs +++ b/src/sys/unix/selector/kqueue.rs @@ -1,5 +1,4 @@ use crate::{Interest, Token}; -use log::error; use std::mem::MaybeUninit; use std::ops::{Deref, DerefMut}; use std::os::unix::io::{AsRawFd, RawFd};