From 3ef1bf27644ede62899eccb3c6dbf39b9f4c3fd0 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Fri, 21 Jun 2024 02:21:04 -0700 Subject: [PATCH] chore: use tracing instead of log crate --- Cargo.toml | 4 +-- src/loop_logic.rs | 57 ++++++++++++++++--------------------- src/sources/mod.rs | 4 +-- src/sources/ping/eventfd.rs | 5 ++-- src/sources/ping/iocp.rs | 13 +++++---- src/sources/ping/pipe.rs | 3 +- src/sources/signals.rs | 5 ++-- 7 files changed, 43 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 648bbaab..97803b35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/src/loop_logic.rs b/src/loop_logic.rs index a4e89085..43cd621a 100644 --- a/src/loop_logic.rs +++ b/src/loop_logic.rs @@ -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}; @@ -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 @@ -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 @@ -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(), @@ -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); } @@ -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 @@ -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); } @@ -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 @@ -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:?}"); } } } @@ -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 @@ -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(), @@ -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(), @@ -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; @@ -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"); } } diff --git a/src/sources/mod.rs b/src/sources/mod.rs index 824ad3b4..58f59b73 100644 --- a/src/sources/mod.rs +++ b/src/sources/mod.rs @@ -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}; @@ -320,7 +320,7 @@ where .. } = *disp; trace!( - "[calloop] Processing events for source type {}", + "Processing events for source type {}", std::any::type_name::() ); source diff --git a/src/sources/ping/eventfd.rs b/src/sources/ping/eventfd.rs index af39d31a..13dd04fd 100644 --- a/src/sources/ping/eventfd.rs +++ b/src/sources/ping/eventfd.rs @@ -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::{ @@ -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:?}"); } } } @@ -188,7 +189,7 @@ struct FlagOnDrop(Arc); 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:?}"); } } } diff --git a/src/sources/ping/iocp.rs b/src/sources/ping/iocp.rs index 16fefa88..5df50865 100644 --- a/src/sources/ping/iocp.rs +++ b/src/sources/ping/iocp.rs @@ -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; @@ -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}"); } } } @@ -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}"); } } } @@ -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 ); @@ -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(()) } diff --git a/src/sources/ping/pipe.rs b/src/sources/ping/pipe.rs index 21591c2d..3cd7eac2 100644 --- a/src/sources/ping/pipe.rs +++ b/src/sources/ping/pipe.rs @@ -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::{ @@ -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:?}"); } } } diff --git a/src/sources/signals.rs b/src/sources/signals.rs index 9fdddce9..5877885e 100644 --- a/src/sources/signals.rs +++ b/src/sources/signals.rs @@ -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}; @@ -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:?}"); } } } @@ -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()); } }