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

chore: use tracing instead of log crate #195

Merged
merged 1 commit into from
Jun 23, 2024
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 @@ -22,11 +22,11 @@ codecov = { repository = "Smithay/calloop" }
async-task = { version = "4.4.0", optional = true }
bitflags = "2.4"
futures-io = { version = "0.3.5", optional = true }
log = "0.4"
pin-utils = { version = "0.1.0", optional = true }
polling = "3.0.0"
slab = "0.4.8"
rustix = { version = "0.38", default-features = false, features = ["event", "fs", "pipe", "std"] }
slab = "0.4.8"
tracing = { version = "0.1.40", default-features = false, features = ["log"] }

[target.'cfg(unix)'.dependencies]
nix = { version = "0.29", default-features = false, features = ["signal"], optional = true }
Expand Down
57 changes: 24 additions & 33 deletions src/loop_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#[cfg(windows)]
use std::os::windows::io::{AsHandle, AsRawHandle, AsSocket as AsFd, BorrowedHandle, RawHandle};

use log::trace;
use polling::Poller;
use tracing::{trace, warn};

use crate::list::{SourceEntry, SourceList};
use crate::sources::{Dispatcher, EventSource, Idle, IdleDispatcher};
Expand Down Expand Up @@ -127,7 +127,7 @@
let slot = sources.vacant_entry();

slot.source = Some(dispatcher.clone_as_event_dispatcher());
trace!("[calloop] Inserting new source #{}", slot.token.get_id());
trace!(source = slot.token.get_id(), "Inserting new source");
let ret = slot.source.as_ref().unwrap().register(
&mut poll,
&mut self
Expand Down Expand Up @@ -171,7 +171,7 @@
source: Some(ref source),
} = self.inner.sources.borrow().get(token.inner)?
{
trace!("[calloop] Registering source #{}", entry_token.get_id());
trace!(source = entry_token.get_id(), "Registering source");
source.register(
&mut self.inner.poll.borrow_mut(),
&mut self
Expand All @@ -196,8 +196,8 @@
} = self.inner.sources.borrow().get(token.inner)?
{
trace!(
"[calloop] Updating registration of source #{}",
entry_token.get_id()
source = entry_token.get_id(),
"Updating registration of source"

Check warning on line 200 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L199-L200

Added lines #L199 - L200 were not covered by tests
);
if !source.reregister(
&mut self.inner.poll.borrow_mut(),
Expand All @@ -207,7 +207,10 @@
.borrow_mut(),
&mut TokenFactory::new(entry_token),
)? {
trace!("[calloop] Cannot do it now, storing for later.");
trace!(
source = entry_token.get_id(),
"Can't update registration withing a callback, storing for later."

Check warning on line 212 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L210-L212

Added lines #L210 - L212 were not covered by tests
);
// we are in a callback, store for later processing
self.inner.pending_action.set(PostAction::Reregister);
}
Expand All @@ -230,7 +233,7 @@
// The token provided by the user is no longer valid
return Err(crate::Error::InvalidToken);
}
trace!("[calloop] Unregistering source #{}", entry_token.get_id());
trace!(source = entry_token.get_id(), "Unregistering source");
if !source.unregister(
&mut self.inner.poll.borrow_mut(),
&mut self
Expand All @@ -239,7 +242,10 @@
.borrow_mut(),
*token,
)? {
trace!("[calloop] Cannot do it now, storing for later.");
trace!(
source = entry_token.get_id(),
"Cannot unregister source in callback, storing for later."

Check warning on line 247 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L245-L247

Added lines #L245 - L247 were not covered by tests
);
// we are in a callback, store for later processing
self.inner.pending_action.set(PostAction::Disable);
}
Expand All @@ -257,7 +263,7 @@
}) = self.inner.sources.borrow_mut().get_mut(token.inner)
{
if let Some(source) = source.take() {
trace!("[calloop] Removing source #{}", entry_token.get_id());
trace!(source = entry_token.get_id(), "Removing source");
if let Err(e) = source.unregister(
&mut self.inner.poll.borrow_mut(),
&mut self
Expand All @@ -266,10 +272,7 @@
.borrow_mut(),
token,
) {
log::warn!(
"[calloop] Failed to unregister source from the polling system: {:?}",
e
);
warn!("Failed to unregister source from the polling system: {e:?}");

Check warning on line 275 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L275

Added line #L275 was not covered by tests
}
}
}
Expand Down Expand Up @@ -438,10 +441,7 @@
.and_then(|entry| entry.source.clone());

if let Some(disp) = opt_disp {
trace!(
"[calloop] Dispatching events for source #{}",
reg_token.get_id()
);
trace!(source = reg_token.get_id(), "Dispatching events for source");
let mut ret = disp.process_events(event.readiness, event.token, data)?;

// if the returned PostAction is Continue, it may be overwritten by an user-specified pending action
Expand All @@ -457,8 +457,8 @@
match ret {
PostAction::Reregister => {
trace!(
"[calloop] Postaction reregister for source #{}",
reg_token.get_id()
source = reg_token.get_id(),
"Postaction reregister for source"

Check warning on line 461 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L460-L461

Added lines #L460 - L461 were not covered by tests
);
disp.reregister(
&mut self.handle.inner.poll.borrow_mut(),
Expand All @@ -472,8 +472,8 @@
}
PostAction::Disable => {
trace!(
"[calloop] Postaction unregister for source #{}",
reg_token.get_id()
source = reg_token.get_id(),
"Postaction unregister for source"

Check warning on line 476 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L475-L476

Added lines #L475 - L476 were not covered by tests
);
disp.unregister(
&mut self.handle.inner.poll.borrow_mut(),
Expand All @@ -486,10 +486,7 @@
)?;
}
PostAction::Remove => {
trace!(
"[calloop] Postaction remove for source #{}",
reg_token.get_id()
);
trace!(source = reg_token.get_id(), "Postaction remove for source");
if let Ok(entry) = self.handle.inner.sources.borrow_mut().get_mut(reg_token)
{
entry.source = None;
Expand Down Expand Up @@ -519,17 +516,11 @@
.borrow_mut(),
RegistrationToken::new(reg_token),
) {
log::warn!(
"[calloop] Failed to unregister source from the polling system: {:?}",
e
);
warn!("Failed to unregister source from the polling system: {e:?}",);

Check warning on line 519 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L519

Added line #L519 was not covered by tests
}
}
} else {
log::warn!(
"[calloop] Received an event for non-existence source: {:?}",
reg_token
);
warn!(?reg_token, "Received an event for non-existence source");

Check warning on line 523 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L523

Added line #L523 was not covered by tests
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
rc::Rc,
};

use log::trace;
use tracing::trace;

pub use crate::loop_logic::EventIterator;
use crate::{sys::TokenFactory, Poll, Readiness, RegistrationToken, Token};
Expand Down Expand Up @@ -320,7 +320,7 @@
..
} = *disp;
trace!(
"[calloop] Processing events for source type {}",
"Processing events for source type {}",

Check warning on line 323 in src/sources/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/sources/mod.rs#L323

Added line #L323 was not covered by tests
std::any::type_name::<S>()
);
source
Expand Down
5 changes: 3 additions & 2 deletions src/sources/ping/eventfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use rustix::event::{eventfd, EventfdFlags};
use rustix::io::{read, write, Errno};
use tracing::warn;

use super::PingError;
use crate::{
Expand Down Expand Up @@ -175,7 +176,7 @@
/// Send a ping to the `PingSource`.
pub fn ping(&self) {
if let Err(e) = send_ping(self.event.0.as_fd(), INCREMENT_PING) {
log::warn!("[calloop] Failed to write a ping: {:?}", e);
warn!("Failed to write a ping: {e:?}");

Check warning on line 179 in src/sources/ping/eventfd.rs

View check run for this annotation

Codecov / codecov/patch

src/sources/ping/eventfd.rs#L179

Added line #L179 was not covered by tests
}
}
}
Expand All @@ -188,7 +189,7 @@
impl Drop for FlagOnDrop {
fn drop(&mut self) {
if let Err(e) = send_ping(self.0.as_fd(), INCREMENT_CLOSE) {
log::warn!("[calloop] Failed to send close ping: {:?}", e);
warn!("Failed to send close ping: {e:?}");

Check warning on line 192 in src/sources/ping/eventfd.rs

View check run for this annotation

Codecov / codecov/patch

src/sources/ping/eventfd.rs#L192

Added line #L192 was not covered by tests
}
}
}
13 changes: 7 additions & 6 deletions src/sources/ping/iocp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::sources::EventSource;

use polling::os::iocp::{CompletionPacket, PollerIocpExt};
use polling::Poller;
use tracing::{trace, warn};

use std::fmt;
use std::io;
Expand Down Expand Up @@ -71,14 +72,14 @@ impl Ping {
let poll_state = match &mut counter.poll_state {
Some(ps) => ps,
None => {
log::warn!("[calloop] ping was not registered with the event loop");
warn!("ping was not registered with the event loop");
return;
}
};

// If we aren't currently inserted in the loop, send our packet.
if let Err(e) = poll_state.notify() {
log::warn!("[calloop] failed to post packet to IOCP: {}", e);
warn!("failed to post packet to IOCP: {e}");
}
}
}
Expand All @@ -90,7 +91,7 @@ impl Drop for Ping {
let mut counter = self.state.counter.lock().unwrap_or_else(|e| e.into_inner());
if let Some(poll_state) = &mut counter.poll_state {
if let Err(e) = poll_state.notify() {
log::warn!("[calloop] failed to post packet to IOCP during drop: {}", e);
warn!("failed to post packet to IOCP during drop: {e}");
}
}
}
Expand Down Expand Up @@ -129,8 +130,8 @@ impl EventSource for PingSource {
// Make sure this is our token.
let token: usize = token.inner.into();
if poll_state.packet.event().key != token {
log::warn!(
"[calloop] token does not match; expected {:x}, got {:x}",
warn!(
"token does not match; expected {:x}, got {:x}",
poll_state.packet.event().key,
token
);
Expand Down Expand Up @@ -227,7 +228,7 @@ impl EventSource for PingSource {

// Remove our current registration.
if counter.poll_state.take().is_none() {
log::trace!("[calloop] unregistered a source that wasn't registered");
trace!("unregistered a source that wasn't registered");
}
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion src/sources/ping/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::os::unix::io::{AsFd, BorrowedFd, OwnedFd};
use std::sync::Arc;

use rustix::io::{read, write, Errno};
use tracing::warn;

use super::PingError;
use crate::{
Expand Down Expand Up @@ -140,7 +141,7 @@ impl Ping {
/// Send a ping to the `PingSource`
pub fn ping(&self) {
if let Err(e) = send_ping(self.pipe.as_fd()) {
log::warn!("[calloop] Failed to write a ping: {:?}", e);
warn!("Failed to write a ping: {e:?}");
}
}
}
5 changes: 3 additions & 2 deletions src/sources/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use nix::sys::signal::SigSet;
use nix::sys::signalfd::{siginfo, SfdFlags, SignalFd};
use tracing::warn;

use super::generic::{FdWrapper, Generic};
use crate::{EventSource, Interest, Mode, Poll, PostAction, Readiness, Token, TokenFactory};
Expand Down Expand Up @@ -277,7 +278,7 @@
fn drop(&mut self) {
// we cannot handle error here
if let Err(e) = self.mask.thread_unblock() {
log::warn!("[calloop] Failed to unmask signals: {:?}", e);
warn!("Failed to unmask signals: {e:?}");

Check warning on line 281 in src/sources/signals.rs

View check run for this annotation

Codecov / codecov/patch

src/sources/signals.rs#L281

Added line #L281 was not covered by tests
}
}
}
Expand All @@ -304,7 +305,7 @@
Ok(Some(info)) => callback(Event { info }, &mut ()),
Ok(None) => break,
Err(e) => {
log::warn!("[callop] Error reading from signalfd: {}", e);
warn!("Error reading from signalfd: {e}");

Check warning on line 308 in src/sources/signals.rs

View check run for this annotation

Codecov / codecov/patch

src/sources/signals.rs#L308

Added line #L308 was not covered by tests
return Err(e.into());
}
}
Expand Down
Loading