Skip to content

Commit

Permalink
m: Replace log with tracing
Browse files Browse the repository at this point in the history
Tracing is a modern replacement for the log crate that allows for
annotating log messages with the function that they come from.

cc #3488

Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull committed Feb 28, 2024
1 parent a4480a0 commit a44e9f8
Show file tree
Hide file tree
Showing 34 changed files with 56 additions and 53 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ cfg_aliases = "0.2.0"
[dependencies]
bitflags = "2"
cursor-icon = "1.1.0"
log = "0.4"
mint = { version = "0.5.6", optional = true }
rwh_04 = { package = "raw-window-handle", version = "0.4", optional = true }
rwh_05 = { package = "raw-window-handle", version = "0.5.2", features = ["std"], optional = true }
rwh_06 = { package = "raw-window-handle", version = "0.6", features = ["std"], optional = true }
serde = { workspace = true, optional = true }
smol_str = "0.2.0"
dpi = { path = "dpi" }
tracing = { version = "0.1.40", default_features = false }

[dev-dependencies]
image = { version = "0.24.0", default-features = false, features = ["png"] }
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/android/keycodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand All @@ -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
}
}
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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,
Expand Down Expand Up @@ -331,7 +331,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:?}");
}
}

Expand Down Expand Up @@ -1015,7 +1015,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)
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/platform_impl/ios/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,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
);
Expand Down Expand Up @@ -677,9 +677,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
);
Expand Down Expand Up @@ -912,7 +912,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
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/ios/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/common/xkb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/wayland/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/wayland/seat/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/wayland/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/wayland/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/wayland/window/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/ime/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/ime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -480,7 +480,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;
Expand Down Expand Up @@ -564,7 +564,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 => {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/util/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/x11/util/randr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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}");
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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"),
}
}

Expand Down Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/xdisplay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/macos/app_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,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");
}
})
}
2 changes: 1 addition & 1 deletion src/platform_impl/macos/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/macos/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/util.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/orbital/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ impl<T: 'static> EventLoop<T> {
}
}
other => {
log::warn!("unhandled event: {:?}", other);
tracing::warn!("unhandled event: {:?}", other);
}
}
}
Expand Down
Loading

0 comments on commit a44e9f8

Please sign in to comment.