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

@ -174,7 +174,7 @@ pub fn character_map_and_combine_key(
let key_map = match app.device_key_character_map(device_id) {
Ok(key_map) => key_map,
Err(err) => {
log::warn!("Failed to look up `KeyCharacterMap` for device {device_id}: {err:?}");
tracing::warn!("Failed to look up `KeyCharacterMap` for device {device_id}: {err:?}");
return None;
}
};
@ -188,7 +188,7 @@ pub fn character_map_and_combine_key(
Ok(Some(key)) => Some(key),
Ok(None) => None,
Err(err) => {
log::warn!("KeyEvent: Failed to combine 'dead key' accent '{accent}' with '{unicode}': {err:?}");
tracing::warn!("KeyEvent: Failed to combine 'dead key' accent '{accent}' with '{unicode}': {err:?}");
None
}
}
@ -213,7 +213,7 @@ pub fn character_map_and_combine_key(
None
}
Err(err) => {
log::warn!("KeyEvent: Failed to get key map character: {err:?}");
tracing::warn!("KeyEvent: Failed to get key map character: {err:?}");
*combining_accent = None;
None
}

View file

@ -16,7 +16,7 @@ use android_activity::input::{InputEvent, KeyAction, Keycode, MotionAction};
use android_activity::{
AndroidApp, AndroidAppWaker, ConfigurationRef, InputStatus, MainEvent, Rect,
};
use log::{debug, trace, warn};
use tracing::{debug, trace, warn};
use crate::{
cursor::Cursor,
@ -330,7 +330,7 @@ impl<T: 'static> EventLoop<T> {
}
},
Err(err) => {
log::warn!("Failed to get input events iterator: {err:?}");
tracing::warn!("Failed to get input events iterator: {err:?}");
}
}
@ -1014,7 +1014,7 @@ impl Window {
if let Some(native_window) = self.app.native_window().as_ref() {
native_window.raw_window_handle()
} else {
log::error!("Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.");
tracing::error!("Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.");
Err(rwh_06::HandleError::Unavailable)
}
}

View file

@ -622,9 +622,9 @@ pub(crate) fn handle_nonuser_events<I: IntoIterator<Item = EventWrapper>>(
match wrapper {
EventWrapper::StaticEvent(event) => {
if !processing_redraws && event.is_redraw() {
log::info!("processing `RedrawRequested` during the main event loop");
tracing::info!("processing `RedrawRequested` during the main event loop");
} else if processing_redraws && !event.is_redraw() {
log::warn!(
tracing::warn!(
"processing non `RedrawRequested` event after the main event loop: {:#?}",
event
);
@ -676,9 +676,9 @@ pub(crate) fn handle_nonuser_events<I: IntoIterator<Item = EventWrapper>>(
match wrapper {
EventWrapper::StaticEvent(event) => {
if !processing_redraws && event.is_redraw() {
log::info!("processing `RedrawRequested` during the main event loop");
tracing::info!("processing `RedrawRequested` during the main event loop");
} else if processing_redraws && !event.is_redraw() {
log::warn!(
tracing::warn!(
"processing non-`RedrawRequested` event after the main event loop: {:#?}",
event
);
@ -911,7 +911,7 @@ macro_rules! os_capabilities {
impl OSCapabilities {$(
$(#[$attr])*
pub fn $error_name(&self, extra_msg: &str) {
log::warn!(
tracing::warn!(
concat!("`", $objc_call, "` requires iOS {}.{}+. This device is running iOS {}.{}.{}. {}"),
$major, $minor, self.os_version.majorVersion, self.os_version.minorVersion, self.os_version.patchVersion,
extra_msg

View file

@ -85,7 +85,7 @@ impl ActiveEventLoop {
pub(crate) fn exit(&self) {
// https://developer.apple.com/library/archive/qa/qa1561/_index.html
// it is not possible to quit an iOS app gracefully and programmatically
log::warn!("`ControlFlow::Exit` ignored on iOS");
tracing::warn!("`ControlFlow::Exit` ignored on iOS");
}
pub(crate) fn exiting(&self) -> bool {

View file

@ -3,10 +3,10 @@
use std::collections::VecDeque;
use icrate::Foundation::{CGFloat, CGPoint, CGRect, CGSize, MainThreadBound, MainThreadMarker};
use log::{debug, warn};
use objc2::rc::Id;
use objc2::runtime::{AnyObject, NSObject};
use objc2::{class, declare_class, msg_send, msg_send_id, mutability, ClassType, DeclaredClass};
use tracing::{debug, warn};
use super::app_state::EventWrapper;
use super::uikit::{

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.

View file

@ -471,10 +471,10 @@ fn window_activation_hack(app: &NSApplication) {
// This way we preserve the user's desired initial visibility status
// TODO: Also filter on the type/"level" of the window, and maybe other things?
if window.isVisible() {
log::trace!("Activating visible window");
tracing::trace!("Activating visible window");
window.makeKeyAndOrderFront(None);
} else {
log::trace!("Skipping activating invisible window");
tracing::trace!("Skipping activating invisible window");
}
})
}

View file

@ -71,7 +71,7 @@ unsafe fn try_cursor_from_selector(sel: Sel) -> Option<Id<NSCursor>> {
let cursor: Id<NSCursor> = unsafe { msg_send_id![cls, performSelector: sel] };
Some(cursor)
} else {
log::warn!("cursor `{sel}` appears to be invalid");
tracing::warn!("cursor `{sel}` appears to be invalid");
None
}
}

View file

@ -36,14 +36,14 @@ pub fn get_modifierless_char(scancode: u16) -> Key {
unsafe {
input_source = ffi::TISCopyCurrentKeyboardLayoutInputSource();
if input_source.is_null() {
log::error!("`TISCopyCurrentKeyboardLayoutInputSource` returned null ptr");
tracing::error!("`TISCopyCurrentKeyboardLayoutInputSource` returned null ptr");
return Key::Unidentified(NativeKey::MacOS(scancode));
}
let layout_data =
ffi::TISGetInputSourceProperty(input_source, ffi::kTISPropertyUnicodeKeyLayoutData);
if layout_data.is_null() {
CFRelease(input_source as *mut c_void);
log::error!("`TISGetInputSourceProperty` returned null ptr");
tracing::error!("`TISGetInputSourceProperty` returned null ptr");
return Key::Unidentified(NativeKey::MacOS(scancode));
}
layout = CFDataGetBytePtr(layout_data as CFDataRef) as *const ffi::UCKeyboardLayout;
@ -71,7 +71,7 @@ pub fn get_modifierless_char(scancode: u16) -> Key {
CFRelease(input_source as *mut c_void);
}
if translate_result != 0 {
log::error!(
tracing::error!(
"`UCKeyTranslate` returned with the non-zero value: {}",
translate_result
);

View file

@ -71,7 +71,7 @@ impl EventHandler {
*data = None;
}
Ok(None) => {
log::error!("tried to clear handler, but no handler was set");
tracing::error!("tried to clear handler, but no handler was set");
}
Err(_) => {
// Note: This is not expected to ever happen, this
@ -125,7 +125,7 @@ impl EventHandler {
// `NSApplication`, our app delegate and this handler are all
// global state and so it's not impossible that we could get
// an event after the application has exited the `EventLoop`.
log::error!("tried to run event handler, but no handler was set");
tracing::error!("tried to run event handler, but no handler was set");
}
Err(_) => {
// Prevent re-entrancy.

View file

@ -1,5 +1,5 @@
use icrate::Foundation::{NSNotFound, NSRange, NSUInteger};
use log::trace;
use tracing::trace;
pub const EMPTY_RANGE: NSRange = NSRange {
location: NSNotFound as NSUInteger,
@ -20,7 +20,7 @@ pub(crate) struct TraceGuard {
impl TraceGuard {
#[inline]
pub(crate) fn new(module_path: &'static str, called_from_fn: &'static str) -> Self {
trace!(target: module_path, "Triggered `{}`", called_from_fn);
trace!(target = module_path, "Triggered `{}`", called_from_fn);
Self {
module_path,
called_from_fn,
@ -31,6 +31,10 @@ impl TraceGuard {
impl Drop for TraceGuard {
#[inline]
fn drop(&mut self) {
trace!(target: self.module_path, "Completed `{}`", self.called_from_fn);
trace!(
target = self.module_path,
"Completed `{}`",
self.called_from_fn
);
}
}

View file

@ -338,7 +338,7 @@ declare_class!(
// Leave the Preedit self.ivars()
self.ivars().ime_state.set(ImeState::Ground);
} else {
log::warn!("Expected to have IME enabled when receiving unmarkText");
tracing::warn!("Expected to have IME enabled when receiving unmarkText");
}
}

View file

@ -537,7 +537,7 @@ impl<T: 'static> EventLoop<T> {
}
}
other => {
log::warn!("unhandled event: {:?}", other);
tracing::warn!("unhandled event: {:?}", other);
}
}
}

View file

@ -301,7 +301,9 @@ impl CursorHandler {
};
}
ImageState::Failed(error) => {
log::error!("trying to load custom cursor that has failed to load: {error}")
tracing::error!(
"trying to load custom cursor that has failed to load: {error}"
)
}
ImageState::Image(_) => {
drop(state);
@ -413,7 +415,7 @@ impl Inner {
self.set_style();
}
ImageState::Failed(error) => {
log::error!("custom cursor failed to load: {error}");
tracing::error!("custom cursor failed to load: {error}");
self.cursor = previous.into()
}
ImageState::Loading { .. } => unreachable!("notified without being ready"),

View file

@ -190,7 +190,7 @@ pub fn key_location(event: &KeyboardEvent) -> KeyLocation {
KeyboardEvent::DOM_KEY_LOCATION_NUMPAD => KeyLocation::Numpad,
KeyboardEvent::DOM_KEY_LOCATION_STANDARD => KeyLocation::Standard,
location => {
log::warn!("Unexpected key location: {location}");
tracing::warn!("Unexpected key location: {location}");
KeyLocation::Standard
}
}

View file

@ -1,5 +1,5 @@
use js_sys::{Array, Object};
use log::warn;
use tracing::warn;
use wasm_bindgen::prelude::{wasm_bindgen, Closure};
use wasm_bindgen::{JsCast, JsValue};
use web_sys::{

View file

@ -18,7 +18,7 @@ use windows_sys::{
},
};
use log::debug;
use tracing::debug;
use crate::platform_impl::platform::{
definitions::{IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknownVtbl},

View file

@ -536,7 +536,7 @@ impl ActiveEventLoop {
let inner = match WinCursor::new(&source.inner.0) {
Ok(cursor) => cursor,
Err(err) => {
log::warn!("Failed to create custom cursor: {err}");
tracing::warn!("Failed to create custom cursor: {err}");
WinCursor::Failed
}
};

View file

@ -32,8 +32,8 @@ use windows_sys::Win32::{
},
};
use log::{trace, warn};
use smol_str::SmolStr;
use tracing::{trace, warn};
use unicode_segmentation::UnicodeSegmentation;
use crate::{

View file

@ -236,7 +236,7 @@ impl MonitorHandle {
let monitor_info = match get_monitor_info(self.0) {
Ok(monitor_info) => monitor_info,
Err(error) => {
log::warn!("Error from get_monitor_info: {error}");
tracing::warn!("Error from get_monitor_info: {error}");
return modes.into_iter().map(mod_map);
}
};

View file

@ -59,7 +59,7 @@ use windows_sys::Win32::{
},
};
use log::warn;
use tracing::warn;
use crate::{
cursor::Cursor,