Skip to content

Commit

Permalink
deps(udp): make tracing optional
Browse files Browse the repository at this point in the history
This commit makes the `tracing` dependency in `quinn-udp` optional, but enabled
by default. If disabled, `log` is used.
  • Loading branch information
mxinden committed Jul 18, 2024
1 parent 411abe9 commit 482381c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ futures-io = "0.3.19"
hdrhistogram = { version = "7.2", default-features = false }
hex-literal = "0.4"
lazy_static = "1"
log = "0.4"
once_cell = "1.19"
pin-project-lite = "0.2"
rand = "0.8"
Expand Down
7 changes: 3 additions & 4 deletions quinn-udp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ workspace = ".."
all-features = true

[features]
default = ["log"]
# Write logs via the `log` crate when no `tracing` subscriber exists
log = ["tracing/log"]
default = ["tracing"]

[dependencies]
libc = "0.2.113"
socket2 = { workspace = true }
tracing = { workspace = true }
tracing = { workspace = true, optional = true }
log = { workspace = true }

[target.'cfg(windows)'.dependencies]
once_cell = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions quinn-udp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ use std::{
time::{Duration, Instant},
};

#[cfg(not(feature = "tracing"))]
use log::warn;
#[cfg(feature = "tracing")]
use tracing::warn;

#[cfg(any(unix, windows))]
Expand Down
9 changes: 7 additions & 2 deletions quinn-udp/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ use std::{

use socket2::SockRef;

#[cfg(not(feature = "tracing"))]
use log::{debug, error};
#[cfg(feature = "tracing")]
use tracing::{debug, error};

use super::{
cmsg, log_sendmsg_error, EcnCodepoint, RecvMeta, Transmit, UdpSockRef, IO_ERROR_LOG_INTERVAL,
};
Expand Down Expand Up @@ -87,7 +92,7 @@ impl UdpSocketState {
if is_ipv4 || !io.only_v6()? {
if let Err(err) = set_socket_option(&*io, libc::IPPROTO_IP, libc::IP_RECVTOS, OPTION_ON)
{
tracing::debug!("Ignoring error setting IP_RECVTOS on socket: {err:?}",);
debug!("Ignoring error setting IP_RECVTOS on socket: {err:?}",);
}
}

Expand Down Expand Up @@ -283,7 +288,7 @@ fn send(
// Prevent new transmits from being scheduled using GSO. Existing GSO transmits
// may already be in the pipeline, so we need to tolerate additional failures.
if state.max_gso_segments() > 1 {
tracing::error!("got transmit error, halting segmentation offload");
error!("got transmit error, halting segmentation offload");
state
.max_gso_segments
.store(1, std::sync::atomic::Ordering::Relaxed);
Expand Down
4 changes: 2 additions & 2 deletions quinn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ runtime-async-std = ["async-io", "async-std"]
runtime-smol = ["async-io", "smol"]

# Write logs via the `log` crate when no `tracing` subscriber exists
log = ["tracing/log", "proto/log", "udp/log"]
log = ["tracing/log", "proto/log"]

[dependencies]
async-io = { workspace = true, optional = true }
Expand All @@ -45,7 +45,7 @@ socket2 = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
tokio = { workspace = true }
udp = { package = "quinn-udp", path = "../quinn-udp", version = "0.5", default-features = false }
udp = { package = "quinn-udp", path = "../quinn-udp", version = "0.5", default-features = false, features = ["tracing"] }

[dev-dependencies]
anyhow = { workspace = true }
Expand Down

0 comments on commit 482381c

Please sign in to comment.