Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make log an optional dependency #1673

Merged
merged 1 commit into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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 = []
Expand All @@ -43,7 +43,7 @@ os-ext = [
net = []

[dependencies]
log = "0.4.8"
log = { version = "0.4.8", optional = true }

[target.'cfg(unix)'.dependencies]
libc = "0.2.121"
Expand Down
24 changes: 24 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*);
}
}
}
}
1 change: 0 additions & 1 deletion src/poll.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/sys/unix/selector/epoll.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{Interest, Token};

use libc::{EPOLLET, EPOLLIN, EPOLLOUT, EPOLLPRI, EPOLLRDHUP};
use log::error;
use std::os::unix::io::{AsRawFd, RawFd};
#[cfg(debug_assertions)]
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
Expand Down
1 change: 0 additions & 1 deletion src/sys/unix/selector/kqueue.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{Interest, Token};
use log::error;
use std::mem::{self, MaybeUninit};
use std::ops::{Deref, DerefMut};
use std::os::unix::io::{AsRawFd, RawFd};
Expand Down