Replace log with tracing

Tracing is a modern replacement for the log crate that allows for
annotating log messages with the function that they come from.

Signed-off-by: John Nunley <dev@notgull.net>
Closes: #3482
This commit is contained in:
John Nunley 2024-02-25 19:20:39 -08:00 committed by Kirill Chibisov
parent 96172693fe
commit 944347696a
44 changed files with 249 additions and 68 deletions

View file

@ -4,10 +4,10 @@ use std::ptr::{self, NonNull};
use std::sync::atomic::{AtomicBool, Ordering};
use crate::utils::Lazy;
use log::warn;
use smol_str::SmolStr;
#[cfg(wayland_platform)]
use std::os::unix::io::OwnedFd;
use tracing::warn;
use xkbcommon_dl::{
self as xkb, xkb_compose_status, xkb_context, xkb_context_flags, xkbcommon_compose_handle,
xkbcommon_handle, XkbCommon, XkbCommonCompose,
@ -451,7 +451,7 @@ fn byte_slice_to_smol_str(bytes: &[u8]) -> Option<SmolStr> {
std::str::from_utf8(bytes)
.map(SmolStr::new)
.map_err(|e| {
log::warn!(
tracing::warn!(
"UTF-8 received from libxkbcommon ({:?}) was invalid: {e}",
bytes
)

View file

@ -687,7 +687,7 @@ unsafe extern "C" fn x_error_callback(
// Don't log error.
if !error_handled {
log::error!("X11 error: {:#?}", error);
tracing::error!("X11 error: {:#?}", error);
// XXX only update the error, if it wasn't handled by any of the hooks.
*xconn.latest_error.lock().unwrap() = Some(error);
}

View file

@ -584,7 +584,7 @@ impl<T: 'static> EventLoop<T> {
};
self.event_loop.dispatch(timeout, state).map_err(|error| {
log::error!("Error dispatching event loop: {}", error);
tracing::error!("Error dispatching event loop: {}", error);
error.into()
})
}

View file

@ -5,7 +5,7 @@ use std::time::Duration;
use calloop::timer::{TimeoutAction, Timer};
use calloop::{LoopHandle, RegistrationToken};
use log::warn;
use tracing::warn;
use sctk::reexports::client::protocol::wl_keyboard::WlKeyboard;
use sctk::reexports::client::protocol::wl_keyboard::{

View file

@ -133,7 +133,7 @@ impl WinitState {
) {
Ok(c) => Some(c),
Err(e) => {
log::warn!("Subcompositor protocol not available, ignoring CSD: {e:?}");
tracing::warn!("Subcompositor protocol not available, ignoring CSD: {e:?}");
None
}
};

View file

@ -14,7 +14,7 @@ use sctk::shell::xdg::window::Window as SctkWindow;
use sctk::shell::xdg::window::WindowDecorations;
use sctk::shell::WaylandSurface;
use log::warn;
use tracing::warn;
use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError};

View file

@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex, Weak};
use std::time::Duration;
use ahash::HashSet;
use log::{info, warn};
use tracing::{info, warn};
use sctk::reexports::client::backend::ObjectId;
use sctk::reexports::client::protocol::wl_seat::WlSeat;
@ -727,7 +727,7 @@ impl WindowState {
RootCustomCursor {
inner: PlatformCustomCursor::X(_),
} => {
log::error!("passed a X11 cursor to Wayland backend");
tracing::error!("passed a X11 cursor to Wayland backend");
return;
}
};

View file

@ -86,7 +86,7 @@ extern "C" fn preedit_draw_callback(
let chg_range =
call_data.chg_first as usize..(call_data.chg_first + call_data.chg_length) as usize;
if chg_range.start > client_data.text.len() || chg_range.end > client_data.text.len() {
log::warn!(
tracing::warn!(
"invalid chg range: buffer length={}, but chg_first={} chg_lengthg={}",
client_data.text.len(),
call_data.chg_first,

View file

@ -10,9 +10,9 @@ use std::sync::{
Arc,
};
use log::debug;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use tracing::debug;
use super::{ffi, util, XConnection, XError};

View file

@ -18,7 +18,7 @@ use calloop::generic::Generic;
use calloop::EventLoop as Loop;
use calloop::{ping::Ping, Readiness};
use libc::{setlocale, LC_CTYPE};
use log::warn;
use tracing::warn;
use x11rb::connection::RequestConnection;
use x11rb::errors::{ConnectError, ConnectionError, IdsExhausted, ReplyError};
@ -483,7 +483,7 @@ impl<T: 'static> EventLoop<T> {
.dispatch(timeout, &mut self.state)
.map_err(std::io::Error::from)
{
log::error!("Failed to poll for events: {error:?}");
tracing::error!("Failed to poll for events: {error:?}");
let exit_code = error.raw_os_error().unwrap_or(1);
self.set_exit_code(exit_code);
return;
@ -567,7 +567,7 @@ impl<T: 'static> EventLoop<T> {
callback(event, &self.event_processor.target)
}
Some(Err(e)) => {
log::error!("Failed to get activation token: {}", e);
tracing::error!("Failed to get activation token: {}", e);
}
None => {}
}

View file

@ -45,7 +45,7 @@ impl XConnection {
self.flush_requests()?;
Ok(true)
} else {
log::error!("Could not select XKB events: The XKB extension is not initialized!");
tracing::error!("Could not select XKB events: The XKB extension is not initialized!");
Ok(false)
}
}

View file

@ -4,7 +4,7 @@ use super::*;
use crate::platform_impl::platform::x11::monitor;
use crate::{dpi::validate_scale_factor, platform_impl::platform::x11::VideoModeHandle};
use log::warn;
use tracing::warn;
use x11rb::protocol::randr::{self, ConnectionExt as _};
/// Represents values of `WINIT_HIDPI_FACTOR`.
@ -44,7 +44,7 @@ impl XConnection {
Ok(Some(dpi)) => return Some(dpi),
Ok(None) => {}
Err(err) => {
log::warn!("failed to fetch XSettings: {err}");
tracing::warn!("failed to fetch XSettings: {err}");
}
}
}

View file

@ -7,7 +7,7 @@ use std::{
sync::{Arc, Mutex, MutexGuard},
};
use log::{debug, info, warn};
use tracing::{debug, info, warn};
use x11rb::{
connection::Connection,
properties::{WmHints, WmSizeHints, WmSizeHintsSpecification},
@ -1573,7 +1573,7 @@ impl UnownedWindow {
#[cfg(wayland_platform)]
Cursor::Custom(RootCustomCursor {
inner: PlatformCustomCursor::Wayland(_),
}) => log::error!("passed a Wayland cursor to X11 backend"),
}) => tracing::error!("passed a Wayland cursor to X11 backend"),
}
}
@ -1857,7 +1857,7 @@ impl UnownedWindow {
)
.expect_then_ignore_error("Failed to send client message");
if let Err(e) = self.xconn.flush_requests() {
log::error!(
tracing::error!(
"`flush` returned an error when focusing the window. Error was: {}",
e
);

View file

@ -121,7 +121,7 @@ impl XConnection {
let xsettings_screen = Self::new_xsettings_screen(&xcb, default_screen);
if xsettings_screen.is_none() {
log::warn!("error setting XSETTINGS; Xft options won't reload automatically")
tracing::warn!("error setting XSETTINGS; Xft options won't reload automatically")
}
// Fetch atoms.