Skip to content

Commit

Permalink
chore: use tracing instead of log crate
Browse files Browse the repository at this point in the history
  • Loading branch information
joshka authored and notgull committed Jun 23, 2024
1 parent 5433747 commit 3ef1bf2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 48 deletions.
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 @@ use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd};
#[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 @@ impl<'l, Data> LoopHandle<'l, Data> {
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 @@ impl<'l, Data> LoopHandle<'l, Data> {
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 @@ impl<'l, Data> LoopHandle<'l, Data> {
} = 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"
);
if !source.reregister(
&mut self.inner.poll.borrow_mut(),
Expand All @@ -207,7 +207,10 @@ impl<'l, Data> LoopHandle<'l, Data> {
.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."
);
// we are in a callback, store for later processing
self.inner.pending_action.set(PostAction::Reregister);
}
Expand All @@ -230,7 +233,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
// 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 @@ impl<'l, Data> LoopHandle<'l, Data> {
.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."
);
// we are in a callback, store for later processing
self.inner.pending_action.set(PostAction::Disable);
}
Expand All @@ -257,7 +263,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
}) = 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 @@ impl<'l, Data> LoopHandle<'l, Data> {
.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:?}");
}
}
}
Expand Down Expand Up @@ -438,10 +441,7 @@ impl<'l, Data> EventLoop<'l, Data> {
.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 @@ impl<'l, Data> EventLoop<'l, Data> {
match ret {
PostAction::Reregister => {
trace!(
"[calloop] Postaction reregister for source #{}",
reg_token.get_id()
source = reg_token.get_id(),
"Postaction reregister for source"
);
disp.reregister(
&mut self.handle.inner.poll.borrow_mut(),
Expand All @@ -472,8 +472,8 @@ impl<'l, Data> EventLoop<'l, Data> {
}
PostAction::Disable => {
trace!(
"[calloop] Postaction unregister for source #{}",
reg_token.get_id()
source = reg_token.get_id(),
"Postaction unregister for source"
);
disp.unregister(
&mut self.handle.inner.poll.borrow_mut(),
Expand All @@ -486,10 +486,7 @@ impl<'l, Data> EventLoop<'l, Data> {
)?;
}
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 @@ impl<'l, Data> EventLoop<'l, Data> {
.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:?}",);
}
}
} else {
log::warn!(
"[calloop] Received an event for non-existence source: {:?}",
reg_token
);
warn!(?reg_token, "Received an event for non-existence source");
}
}

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 @@ use std::{
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 @@ where
..
} = *disp;
trace!(
"[calloop] Processing events for source type {}",
"Processing events for source type {}",
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 std::sync::Arc;

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 @@ impl Ping {
/// 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:?}");
}
}
}
Expand All @@ -188,7 +189,7 @@ struct FlagOnDrop(Arc<OwnedFd>);
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:?}");
}
}
}
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 std::os::raw::c_int;

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 @@ impl Drop for Signals {
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:?}");
}
}
}
Expand All @@ -304,7 +305,7 @@ impl EventSource for Signals {
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}");
return Err(e.into());
}
}
Expand Down

0 comments on commit 3ef1bf2

Please sign in to comment.