From fd77b063134f916f329bf1fec901f913872143c9 Mon Sep 17 00:00:00 2001 From: Olivier FAURE Date: Wed, 3 Feb 2021 19:44:41 +0100 Subject: [PATCH] Switch to trace-based logging * Add dependency to `tracing` * Convert `log::foobar` calls to `tracing::foobar` * Add dev-dependency to `test-env-log` * Replace `console_log` with `tracing-wasm` --- CHANGELOG.md | 3 + README.md | 2 +- druid-shell/Cargo.toml | 5 +- druid-shell/examples/invalidate.rs | 2 +- druid-shell/examples/perftest.rs | 2 +- druid-shell/examples/quit.rs | 4 +- druid-shell/examples/shello.rs | 2 +- druid-shell/src/hotkey.rs | 2 +- druid-shell/src/platform/gtk/application.rs | 2 +- druid-shell/src/platform/gtk/clipboard.rs | 4 +- druid-shell/src/platform/gtk/dialog.rs | 4 +- druid-shell/src/platform/gtk/menu.rs | 2 +- druid-shell/src/platform/gtk/window.rs | 27 +++--- druid-shell/src/platform/mac/application.rs | 2 +- druid-shell/src/platform/mac/clipboard.rs | 6 +- druid-shell/src/platform/mac/dialog.rs | 2 +- druid-shell/src/platform/mac/menu.rs | 2 + druid-shell/src/platform/mac/screen.rs | 1 + druid-shell/src/platform/mac/window.rs | 8 +- druid-shell/src/platform/web/clipboard.rs | 12 +-- druid-shell/src/platform/web/menu.rs | 6 +- druid-shell/src/platform/web/screen.rs | 2 +- druid-shell/src/platform/web/window.rs | 46 ++++----- .../src/platform/windows/application.rs | 6 +- druid-shell/src/platform/windows/clipboard.rs | 20 ++-- druid-shell/src/platform/windows/dcomp.rs | 2 +- druid-shell/src/platform/windows/dialog.rs | 2 +- druid-shell/src/platform/windows/keycodes.rs | 1 + druid-shell/src/platform/windows/menu.rs | 2 +- druid-shell/src/platform/windows/screen.rs | 2 +- druid-shell/src/platform/windows/util.rs | 6 +- druid-shell/src/platform/windows/window.rs | 18 ++-- druid-shell/src/platform/x11/application.rs | 26 ++--- druid-shell/src/platform/x11/clipboard.rs | 13 +-- druid-shell/src/platform/x11/menu.rs | 10 +- druid-shell/src/platform/x11/screen.rs | 2 +- druid-shell/src/platform/x11/util.rs | 4 +- druid-shell/src/platform/x11/window.rs | 96 +++++++++---------- druid-shell/src/util.rs | 6 +- druid/Cargo.toml | 7 +- druid/examples/anim.rs | 2 +- druid/examples/async_event.rs | 2 +- druid/examples/calc.rs | 2 +- druid/examples/cursor.rs | 2 +- druid/examples/custom_widget.rs | 2 +- druid/examples/either.rs | 2 +- druid/examples/event_viewer.rs | 2 +- druid/examples/flex.rs | 2 +- druid/examples/game_of_life.rs | 2 +- druid/examples/hello.rs | 2 +- druid/examples/identity.rs | 2 +- druid/examples/image.rs | 2 +- druid/examples/invalidation.rs | 2 +- druid/examples/layout.rs | 2 +- druid/examples/list.rs | 2 +- druid/examples/markdown_preview.rs | 2 +- druid/examples/multiwin.rs | 4 +- druid/examples/open_save.rs | 2 +- druid/examples/panels.rs | 2 +- druid/examples/scroll.rs | 2 +- druid/examples/scroll_colors.rs | 2 +- druid/examples/split_demo.rs | 2 +- druid/examples/styled_text.rs | 2 +- druid/examples/sub_window.rs | 8 +- druid/examples/svg.rs | 4 +- druid/examples/switches.rs | 2 +- druid/examples/tabs.rs | 4 +- druid/examples/text.rs | 2 +- druid/examples/timer.rs | 2 +- druid/examples/value_formatting/src/main.rs | 2 +- druid/examples/view_switcher.rs | 2 +- druid/examples/web/Cargo.toml | 2 +- druid/examples/widget_gallery.rs | 2 +- druid/src/app.rs | 43 ++++++++- druid/src/bloom.rs | 1 + druid/src/box_constraints.rs | 9 +- druid/src/command.rs | 1 + druid/src/contexts.rs | 10 +- druid/src/core.rs | 13 +-- druid/src/data.rs | 1 + druid/src/env.rs | 1 + druid/src/localization.rs | 4 +- druid/src/menu.rs | 2 +- druid/src/sub_window.rs | 2 +- druid/src/tests/harness.rs | 2 +- druid/src/tests/invalidation_tests.rs | 1 + druid/src/tests/layout_tests.rs | 1 + druid/src/text/attribute.rs | 1 + druid/src/text/editable_text.rs | 1 + druid/src/text/editor.rs | 3 +- druid/src/util.rs | 6 +- druid/src/widget/align.rs | 4 +- druid/src/widget/clip_box.rs | 2 + druid/src/widget/flex.rs | 7 +- druid/src/widget/image.rs | 4 +- druid/src/widget/label.rs | 2 +- druid/src/widget/scroll.rs | 4 +- druid/src/widget/sized_box.rs | 5 +- druid/src/widget/split.rs | 4 +- druid/src/widget/svg.rs | 11 ++- druid/src/widget/tabs.rs | 2 +- druid/src/widget/textbox.rs | 4 +- druid/src/widget/widget_ext.rs | 1 + druid/src/win_handler.rs | 20 ++-- druid/src/window.rs | 8 +- 105 files changed, 355 insertions(+), 274 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d770677259..c5ae15e723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ You can find its changes [documented below](#070---2021-01-01). - Warn on unhandled Commands ([#1533] by [@Maan2003]) - `WindowDesc::new` takes the root widget directly instead of a closure ([#1559] by [@lassipulkkinen]) +- Switch to trace-based logging ([#1562] by [@PoignardAzur]) ### Deprecated @@ -413,6 +414,7 @@ Last release without a changelog :( [@derekdreery]: https://github.com/derekdreery [@MaximilianKoestler]: https://github.com/MaximilianKoestler [@lassipulkkinen]: https://github.com/lassipulkkinen +[@Poignardazur]: https://github.com/PoignardAzur [#599]: https://github.com/linebender/druid/pull/599 [#611]: https://github.com/linebender/druid/pull/611 @@ -611,6 +613,7 @@ Last release without a changelog :( [#1534]: https://github.com/linebender/druid/pull/1534 [#1254]: https://github.com/linebender/druid/pull/1254 [#1559]: https://github.com/linebender/druid/pull/1559 +[#1562]: https://github.com/linebender/druid/pull/1562 [Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master [0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0 diff --git a/README.md b/README.md index 170036a7ba..be3827b818 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ fn main() -> Result<(), PlatformError> { let main_window = WindowDesc::new(ui_builder()); let data = 0_u32; AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(data) } diff --git a/druid-shell/Cargo.toml b/druid-shell/Cargo.toml index 3fb678e306..a88b21abb3 100755 --- a/druid-shell/Cargo.toml +++ b/druid-shell/Cargo.toml @@ -41,7 +41,7 @@ hdr = ["piet-common/hdr"] piet-common = "=0.3.2" kurbo = "0.7.1" -log = "0.4.11" +tracing = "0.1.22" lazy_static = "1.4.0" time = "0.2.16" cfg-if = "1.0.0" @@ -97,5 +97,6 @@ features = ["Window", "MouseEvent", "CssStyleDeclaration", "WheelEvent", "KeyEve [dev-dependencies] piet-common = { version = "=0.3.2", features = ["png"] } -simple_logger = { version = "1.9.0", default-features = false } static_assertions = "1.1.0" +test-env-log = { version = "0.2.5", features = ["trace"], default-features = false } +tracing-subscriber = "0.2.15" diff --git a/druid-shell/examples/invalidate.rs b/druid-shell/examples/invalidate.rs index c9c37cbc98..78325a6a2c 100644 --- a/druid-shell/examples/invalidate.rs +++ b/druid-shell/examples/invalidate.rs @@ -102,7 +102,7 @@ impl WinHandler for InvalidateTest { } fn main() { - simple_logger::SimpleLogger::new().init().unwrap(); + tracing_subscriber::fmt().init(); let app = Application::new().unwrap(); let mut builder = WindowBuilder::new(app.clone()); let inv_test = InvalidateTest { diff --git a/druid-shell/examples/perftest.rs b/druid-shell/examples/perftest.rs index 1c2ebe1abd..27a2a239fb 100644 --- a/druid-shell/examples/perftest.rs +++ b/druid-shell/examples/perftest.rs @@ -136,7 +136,7 @@ impl WinHandler for PerfTest { } fn main() { - simple_logger::SimpleLogger::new().init().unwrap(); + tracing_subscriber::fmt().init(); let app = Application::new().unwrap(); let mut builder = WindowBuilder::new(app.clone()); let perf_test = PerfTest { diff --git a/druid-shell/examples/quit.rs b/druid-shell/examples/quit.rs index 37c92b4b06..260dbada32 100644 --- a/druid-shell/examples/quit.rs +++ b/druid-shell/examples/quit.rs @@ -53,7 +53,7 @@ impl WinHandler for QuitState { if self.quit_count >= 5 { self.handle.close(); } else { - log::info!("Don't wanna quit"); + tracing::info!("Don't wanna quit"); } } @@ -67,7 +67,7 @@ impl WinHandler for QuitState { } fn main() { - simple_logger::SimpleLogger::new().init().unwrap(); + tracing_subscriber::fmt().init(); let app = Application::new().unwrap(); let mut file_menu = Menu::new(); file_menu.add_item( diff --git a/druid-shell/examples/shello.rs b/druid-shell/examples/shello.rs index 01dec133b1..d2fdd68716 100644 --- a/druid-shell/examples/shello.rs +++ b/druid-shell/examples/shello.rs @@ -122,7 +122,7 @@ impl WinHandler for HelloState { } fn main() { - simple_logger::SimpleLogger::new().init().unwrap(); + tracing_subscriber::fmt().init(); let mut file_menu = Menu::new(); file_menu.add_item( 0x100, diff --git a/druid-shell/src/hotkey.rs b/druid-shell/src/hotkey.rs index 0b41289d82..c4dedb3a58 100644 --- a/druid-shell/src/hotkey.rs +++ b/druid-shell/src/hotkey.rs @@ -16,7 +16,7 @@ use std::borrow::Borrow; -use log::warn; +use tracing::warn; use crate::{IntoKey, KbKey, KeyEvent, Modifiers}; diff --git a/druid-shell/src/platform/gtk/application.rs b/druid-shell/src/platform/gtk/application.rs index 4697acc0e5..1678f48e08 100644 --- a/druid-shell/src/platform/gtk/application.rs +++ b/druid-shell/src/platform/gtk/application.rs @@ -45,7 +45,7 @@ impl Application { }; gtk_app.connect_activate(|_app| { - log::info!("gtk: Activated application"); + tracing::info!("gtk: Activated application"); }); if let Err(err) = gtk_app.register(None as Option<&Cancellable>) { diff --git a/druid-shell/src/platform/gtk/clipboard.rs b/druid-shell/src/platform/gtk/clipboard.rs index 1927d894e9..e1d211ad1a 100644 --- a/druid-shell/src/platform/gtk/clipboard.rs +++ b/druid-shell/src/platform/gtk/clipboard.rs @@ -40,7 +40,7 @@ impl Clipboard { // to move it into the closure. :/ let formats = formats.to_owned(); let success = clipboard.set_with_data(&entries, move |_, sel, idx| { - log::info!("got paste callback {}", idx); + tracing::info!("got paste callback {}", idx); let idx = idx as usize; if idx < formats.len() { let item = &formats[idx]; @@ -54,7 +54,7 @@ impl Clipboard { } }); if !success { - log::warn!("failed to set clipboard data."); + tracing::warn!("failed to set clipboard data."); } } diff --git a/druid-shell/src/platform/gtk/dialog.rs b/druid-shell/src/platform/gtk/dialog.rs index 0232ef98f2..d0ea7b42b5 100644 --- a/druid-shell/src/platform/gtk/dialog.rs +++ b/druid-shell/src/platform/gtk/dialog.rs @@ -84,7 +84,7 @@ pub(crate) fn get_file_dialog_path( if let Some(dt) = &options.default_type { if !found_default_filter { - log::warn!("The default type {:?} is not present in allowed types.", dt); + tracing::warn!("The default type {:?} is not present in allowed types.", dt); } } } @@ -102,7 +102,7 @@ pub(crate) fn get_file_dialog_path( }, ResponseType::Cancel => Err(anyhow!("Dialog was deleted")), _ => { - log::warn!("Unhandled dialog result: {:?}", result); + tracing::warn!("Unhandled dialog result: {:?}", result); Err(anyhow!("Unhandled dialog result")) } }; diff --git a/druid-shell/src/platform/gtk/menu.rs b/druid-shell/src/platform/gtk/menu.rs index 4a60ad9c00..affeb6e5bc 100644 --- a/druid-shell/src/platform/gtk/menu.rs +++ b/druid-shell/src/platform/gtk/menu.rs @@ -149,7 +149,7 @@ fn register_accelerator(item: &GtkMenuItem, accel_group: &AccelGroup, menu_key: if let Some(gdk_key) = keycodes::key_to_raw_key(k) { *gdk_key } else { - log::warn!("Cannot map key {:?}", k); + tracing::warn!("Cannot map key {:?}", k); return; } } diff --git a/druid-shell/src/platform/gtk/window.rs b/druid-shell/src/platform/gtk/window.rs index 0a235ca2f9..95517ac63f 100644 --- a/druid-shell/src/platform/gtk/window.rs +++ b/druid-shell/src/platform/gtk/window.rs @@ -31,6 +31,7 @@ use gdk::{EventKey, EventMask, ModifierType, ScrollDirection, WindowExt, WindowT use gio::ApplicationExt; use gtk::prelude::*; use gtk::{AccelGroup, ApplicationWindow, DrawingArea, SettingsExt}; +use tracing::{error, warn}; use crate::kurbo::{Insets, Point, Rect, Size, Vec2}; use crate::piet::{Piet, PietText, RenderContext}; @@ -354,7 +355,7 @@ impl WindowBuilder { let size_dp = area.size_dp(); state.area.set(area); if let Err(e) = state.resize_surface(extents.width, extents.height) { - log::error!("Failed to resize surface: {}", e); + error!("Failed to resize surface: {}", e); } state.with_handler(|h| h.size(size_dp)); state.invalidate_rect(size_dp.to_rect()); @@ -365,7 +366,7 @@ impl WindowBuilder { let invalid = match state.invalid.try_borrow_mut() { Ok(mut invalid) => std::mem::replace(&mut *invalid, Region::EMPTY), Err(_) => { - log::error!("invalid region borrowed while drawing"); + error!("invalid region borrowed while drawing"); Region::EMPTY } }; @@ -389,7 +390,7 @@ impl WindowBuilder { let mut piet_context = Piet::new(&surface_context); handler.paint(&mut piet_context, &invalid); if let Err(e) = piet_context.finish() { - log::error!("piet error on render: {:?}", e); + error!("piet error on render: {:?}", e); } // Copy the entire surface to the drawing area (not just the invalid @@ -401,7 +402,7 @@ impl WindowBuilder { context.fill(); }); } else { - log::warn!("Drawing was skipped because there was no surface"); + warn!("Drawing was skipped because there was no surface"); } } @@ -666,7 +667,7 @@ impl WindowState { #[track_caller] fn with_handler T>(&self, f: F) -> Option { if self.invalid.try_borrow_mut().is_err() || self.surface.try_borrow_mut().is_err() { - log::error!("other RefCells were borrowed when calling into the handler"); + error!("other RefCells were borrowed when calling into the handler"); return None; } @@ -684,7 +685,7 @@ impl WindowState { match self.handler.try_borrow_mut() { Ok(mut h) => Some(f(&mut **h)), Err(_) => { - log::error!("failed to borrow WinHandler at {}", Location::caller()); + error!("failed to borrow WinHandler at {}", Location::caller()); None } } @@ -737,7 +738,7 @@ impl WindowState { region.add_rect(rect); self.window.queue_draw(); } else { - log::warn!("Not invalidating rect because region already borrowed"); + warn!("Not invalidating rect because region already borrowed"); } } @@ -819,7 +820,7 @@ impl WindowHandle { } pub fn content_insets(&self) -> Insets { - log::warn!("WindowHandle::content_insets unimplemented for GTK platforms."); + warn!("WindowHandle::content_insets unimplemented for GTK platforms."); Insets::ZERO } @@ -847,7 +848,7 @@ impl WindowHandle { let (x, y) = state.window.get_size(); Size::new(x as f64, y as f64) } else { - log::warn!("Could not get size for GTK window"); + warn!("Could not get size for GTK window"); Size::new(0., 0.) } } @@ -885,7 +886,7 @@ impl WindowHandle { } pub fn handle_titlebar(&self, _val: bool) { - log::warn!("WindowHandle::handle_titlebar is currently unimplemented for gtk."); + warn!("WindowHandle::handle_titlebar is currently unimplemented for gtk."); } /// Close the window. @@ -939,7 +940,7 @@ impl WindowHandle { let interval = match u32::try_from(interval) { Ok(iv) => iv, Err(_) => { - log::warn!("timer duration exceeds gtk max of 2^32 millis"); + warn!("timer duration exceeds gtk max of 2^32 millis"); u32::max_value() } }; @@ -1125,7 +1126,7 @@ fn run_idle(state: &Arc) -> glib::source::Continue { }); if result.is_none() { - log::warn!("Delaying idle callbacks because the handler is borrowed."); + warn!("Delaying idle callbacks because the handler is borrowed."); // Keep trying to reschedule this idle callback, because we haven't had a chance // to empty the idle queue. Returning glib::source::Continue(true) achieves this but // causes 100% CPU usage, apparently because glib likes to call us back very quickly. @@ -1198,7 +1199,7 @@ fn get_mouse_click_count(event_type: gdk::EventType) -> u8 { gdk::EventType::TripleButtonPress => 3, gdk::EventType::ButtonRelease => 0, _ => { - log::warn!("Unexpected mouse click event type: {:?}", event_type); + warn!("Unexpected mouse click event type: {:?}", event_type); 0 } } diff --git a/druid-shell/src/platform/mac/application.rs b/druid-shell/src/platform/mac/application.rs index bd8efa2f63..87cc8cf886 100644 --- a/druid-shell/src/platform/mac/application.rs +++ b/druid-shell/src/platform/mac/application.rs @@ -97,7 +97,7 @@ impl Application { } } } else { - log::warn!("Application state already borrowed"); + tracing::warn!("Application state already borrowed"); } } diff --git a/druid-shell/src/platform/mac/clipboard.rs b/druid-shell/src/platform/mac/clipboard.rs index 6606bbb8ed..920660e261 100644 --- a/druid-shell/src/platform/mac/clipboard.rs +++ b/druid-shell/src/platform/mac/clipboard.rs @@ -39,7 +39,7 @@ impl Clipboard { let result: BOOL = msg_send![pasteboard, setString: nsstring forType: NSPasteboardTypeString]; if result != YES { - log::warn!("failed to set clipboard"); + tracing::warn!("failed to set clipboard"); } } } @@ -61,7 +61,7 @@ impl Clipboard { let data_type = idents[i]; let result: BOOL = msg_send![pasteboard, setData: data forType: data_type]; if result != YES { - log::warn!( + tracing::warn!( "failed to set clipboard contents for type '{}'", format.identifier ); @@ -100,7 +100,7 @@ impl Clipboard { let idx: NSUInteger = msg_send![array, indexOfObject: available]; let idx = idx as usize; if idx > formats.len() { - log::error!("clipboard object not found"); + tracing::error!("clipboard object not found"); None } else { Some(formats[idx]) diff --git a/druid-shell/src/platform/mac/dialog.rs b/druid-shell/src/platform/mac/dialog.rs index b1792e14bc..dfa4e520d0 100644 --- a/druid-shell/src/platform/mac/dialog.rs +++ b/druid-shell/src/platform/mac/dialog.rs @@ -121,7 +121,7 @@ pub(crate) unsafe fn build_panel(ty: FileDialogType, mut options: FileDialogOpti } } if !present { - log::warn!("The default type {:?} is not present in allowed types.", dt); + tracing::warn!("The default type {:?} is not present in allowed types.", dt); } } diff --git a/druid-shell/src/platform/mac/menu.rs b/druid-shell/src/platform/mac/menu.rs index bfd54f5b49..8a9f99c5e1 100644 --- a/druid-shell/src/platform/mac/menu.rs +++ b/druid-shell/src/platform/mac/menu.rs @@ -179,6 +179,8 @@ impl HotKey { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; + #[test] fn strip_access() { assert_eq!(strip_access_key("&Exit").as_str(), "Exit"); diff --git a/druid-shell/src/platform/mac/screen.rs b/druid-shell/src/platform/mac/screen.rs index ad1daf7c46..5e56998e38 100644 --- a/druid-shell/src/platform/mac/screen.rs +++ b/druid-shell/src/platform/mac/screen.rs @@ -74,6 +74,7 @@ mod test { use crate::platform::mac::screen::transform_coords; use crate::Monitor; use kurbo::Rect; + use test_env_log::test; fn pair(rect: Rect) -> (Rect, Rect) { (rect, rect) diff --git a/druid-shell/src/platform/mac/window.rs b/druid-shell/src/platform/mac/window.rs index ed74eeff5f..6e64628e54 100644 --- a/druid-shell/src/platform/mac/window.rs +++ b/druid-shell/src/platform/mac/window.rs @@ -34,11 +34,11 @@ use cocoa::foundation::{ use core_graphics::context::CGContextRef; use foreign_types::ForeignTypeRef; use lazy_static::lazy_static; -use log::{error, info}; use objc::declare::ClassDecl; use objc::rc::WeakPtr; use objc::runtime::{Class, Object, Sel}; use objc::{class, msg_send, sel, sel_impl}; +use tracing::{debug, error, info}; use crate::kurbo::{Insets, Point, Rect, Size, Vec2}; use crate::piet::{Piet, PietText, RenderContext}; @@ -799,7 +799,7 @@ fn set_position_deferred(this: &mut Object, _view_state: &mut ViewState, positio let screen_height = crate::Screen::get_display_rect().height(); new_frame.origin.y = screen_height - position.y - frame.size.height; // Flip back let () = msg_send![window, setFrame: new_frame display: YES]; - log::debug!("set_position_deferred {:?}", position); + debug!("set_position_deferred {:?}", position); } } @@ -972,7 +972,7 @@ impl WindowHandle { } pub fn make_cursor(&self, _cursor_desc: &CursorDesc) -> Option { - log::warn!("Custom cursors are not yet supported in the macOS backend"); + tracing::warn!("Custom cursors are not yet supported in the macOS backend"); None } @@ -1156,7 +1156,7 @@ impl WindowHandle { } pub fn handle_titlebar(&self, _val: bool) { - log::warn!("WindowHandle::handle_titlebar is currently unimplemented for Mac."); + tracing::warn!("WindowHandle::handle_titlebar is currently unimplemented for Mac."); } pub fn resizable(&self, resizable: bool) { diff --git a/druid-shell/src/platform/web/clipboard.rs b/druid-shell/src/platform/web/clipboard.rs index 32fb32d01a..76cd2fd755 100644 --- a/druid-shell/src/platform/web/clipboard.rs +++ b/druid-shell/src/platform/web/clipboard.rs @@ -23,24 +23,24 @@ pub struct Clipboard; impl Clipboard { /// Put a string onto the system clipboard. pub fn put_string(&mut self, _s: impl AsRef) { - log::warn!("unimplemented"); + tracing::warn!("unimplemented"); } /// Put multi-format data on the system clipboard. pub fn put_formats(&mut self, _formats: &[ClipboardFormat]) { - log::warn!("unimplemented"); + tracing::warn!("unimplemented"); } /// Get a string from the system clipboard, if one is available. pub fn get_string(&self) -> Option { - log::warn!("unimplemented"); + tracing::warn!("unimplemented"); None } /// Given a list of supported clipboard types, returns the supported type which has /// highest priority on the system clipboard, or `None` if no types are supported. pub fn preferred_format(&self, _formats: &[FormatId]) -> Option { - log::warn!("unimplemented"); + tracing::warn!("unimplemented"); None } @@ -49,12 +49,12 @@ impl Clipboard { /// It is recommended that the `fmt` argument be a format returned by /// [`Clipboard::preferred_format`] pub fn get_format(&self, _format: FormatId) -> Option> { - log::warn!("unimplemented"); + tracing::warn!("unimplemented"); None } pub fn available_type_names(&self) -> Vec { - log::warn!("unimplemented"); + tracing::warn!("unimplemented"); Vec::new() } } diff --git a/druid-shell/src/platform/web/menu.rs b/druid-shell/src/platform/web/menu.rs index 61e9ddc5f5..4d37b85c6e 100644 --- a/druid-shell/src/platform/web/menu.rs +++ b/druid-shell/src/platform/web/menu.rs @@ -36,7 +36,7 @@ impl Menu { } pub fn add_dropdown(&mut self, _menu: Menu, _text: &str, _enabled: bool) { - log::warn!("unimplemented"); + tracing::warn!("unimplemented"); } pub fn add_item( @@ -47,10 +47,10 @@ impl Menu { _enabled: bool, _selected: bool, ) { - log::warn!("unimplemented"); + tracing::warn!("unimplemented"); } pub fn add_separator(&mut self) { - log::warn!("unimplemented"); + tracing::warn!("unimplemented"); } } diff --git a/druid-shell/src/platform/web/screen.rs b/druid-shell/src/platform/web/screen.rs index 6240153c7b..0da80f8cad 100644 --- a/druid-shell/src/platform/web/screen.rs +++ b/druid-shell/src/platform/web/screen.rs @@ -17,6 +17,6 @@ use crate::screen::Monitor; pub(crate) fn get_monitors() -> Vec { - log::warn!("Screen::get_monitors() is not implemented for web."); + tracing::warn!("Screen::get_monitors() is not implemented for web."); Vec::new() } diff --git a/druid-shell/src/platform/web/window.rs b/druid-shell/src/platform/web/window.rs index 3e16852106..09ec7c316f 100644 --- a/druid-shell/src/platform/web/window.rs +++ b/druid-shell/src/platform/web/window.rs @@ -21,7 +21,7 @@ use std::rc::{Rc, Weak}; use std::sync::{Arc, Mutex}; use instant::Instant; - +use tracing::{error, warn}; use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; @@ -115,10 +115,10 @@ impl WindowState { self.handler.borrow_mut().paint(&mut ctx, &invalid); Ok(()) }) { - log::error!("piet error on render: {:?}", e); + error!("piet error on render: {:?}", e); } if let Err(e) = piet_ctx.finish() { - log::error!("piet error finishing render: {:?}", e); + error!("piet error finishing render: {:?}", e); } self.invalid.borrow_mut().clear(); } @@ -238,7 +238,7 @@ fn setup_scroll_callback(ws: &Rc) { Vec2::new(size_dp.width * dx, size_dp.height * dy) } _ => { - log::warn!("Invalid deltaMode in WheelEvent: {}", delta_mode); + warn!("Invalid deltaMode in WheelEvent: {}", delta_mode); return; } }; @@ -448,51 +448,51 @@ impl WindowHandle { } pub fn resizable(&self, _resizable: bool) { - log::warn!("resizable unimplemented for web"); + warn!("resizable unimplemented for web"); } pub fn show_titlebar(&self, _show_titlebar: bool) { - log::warn!("show_titlebar unimplemented for web"); + warn!("show_titlebar unimplemented for web"); } pub fn set_position(&self, _position: Point) { - log::warn!("WindowHandle::set_position unimplemented for web"); + warn!("WindowHandle::set_position unimplemented for web"); } pub fn set_level(&self, _level: WindowLevel) { - log::warn!("WindowHandle::set_level is currently unimplemented for web."); + warn!("WindowHandle::set_level is currently unimplemented for web."); } pub fn get_position(&self) -> Point { - log::warn!("WindowHandle::get_position unimplemented for web."); + warn!("WindowHandle::get_position unimplemented for web."); Point::new(0.0, 0.0) } pub fn set_size(&self, _size: Size) { - log::warn!("WindowHandle::set_size unimplemented for web."); + warn!("WindowHandle::set_size unimplemented for web."); } pub fn get_size(&self) -> Size { - log::warn!("WindowHandle::get_size unimplemented for web."); + warn!("WindowHandle::get_size unimplemented for web."); Size::new(0.0, 0.0) } pub fn content_insets(&self) -> Insets { - log::warn!("WindowHandle::content_insets unimplemented for web."); + warn!("WindowHandle::content_insets unimplemented for web."); Insets::ZERO } pub fn set_window_state(&self, _state: window::WindowState) { - log::warn!("WindowHandle::set_window_state unimplemented for web."); + warn!("WindowHandle::set_window_state unimplemented for web."); } pub fn get_window_state(&self) -> window::WindowState { - log::warn!("WindowHandle::get_window_state unimplemented for web."); + warn!("WindowHandle::get_window_state unimplemented for web."); window::WindowState::RESTORED } pub fn handle_titlebar(&self, _val: bool) { - log::warn!("WindowHandle::handle_titlebar unimplemented for web."); + warn!("WindowHandle::handle_titlebar unimplemented for web."); } pub fn close(&self) { @@ -500,7 +500,7 @@ impl WindowHandle { } pub fn bring_to_front_and_focus(&self) { - log::warn!("bring_to_frontand_focus unimplemented for web"); + warn!("bring_to_frontand_focus unimplemented for web"); } pub fn request_anim_frame(&self) { @@ -538,7 +538,7 @@ impl WindowHandle { let interval = match i32::try_from(interval) { Ok(iv) => iv, Err(_) => { - log::warn!("Timer duration exceeds 32 bit integer max"); + warn!("Timer duration exceeds 32 bit integer max"); i32::max_value() } }; @@ -570,17 +570,17 @@ impl WindowHandle { } pub fn make_cursor(&self, _cursor_desc: &CursorDesc) -> Option { - log::warn!("Custom cursors are not yet supported in the web backend"); + warn!("Custom cursors are not yet supported in the web backend"); None } pub fn open_file(&mut self, _options: FileDialogOptions) -> Option { - log::warn!("open_file is currently unimplemented for web."); + warn!("open_file is currently unimplemented for web."); None } pub fn save_as(&mut self, _options: FileDialogOptions) -> Option { - log::warn!("save_as is currently unimplemented for web."); + warn!("save_as is currently unimplemented for web."); None } @@ -621,11 +621,11 @@ impl WindowHandle { } pub fn set_menu(&self, _menu: Menu) { - log::warn!("set_menu unimplemented for web"); + warn!("set_menu unimplemented for web"); } pub fn show_context_menu(&self, _menu: Menu, _pos: Point) { - log::warn!("show_context_menu unimplemented for web"); + warn!("show_context_menu unimplemented for web"); } pub fn set_title(&self, title: impl Into) { @@ -723,5 +723,5 @@ fn set_cursor(canvas: &web_sys::HtmlCanvasElement, cursor: &Cursor) { Cursor::Custom(_) => "default", }, ) - .unwrap_or_else(|_| log::warn!("Failed to set cursor")); + .unwrap_or_else(|_| warn!("Failed to set cursor")); } diff --git a/druid-shell/src/platform/windows/application.rs b/druid-shell/src/platform/windows/application.rs index 28aeced426..8bca0e8cbb 100644 --- a/druid-shell/src/platform/windows/application.rs +++ b/druid-shell/src/platform/windows/application.rs @@ -129,7 +129,7 @@ impl Application { let res = GetMessageW(msg.as_mut_ptr(), ptr::null_mut(), 0, 0); if res <= 0 { if res == -1 { - log::error!( + tracing::error!( "GetMessageW failed: {}", Error::Hr(HRESULT_FROM_WIN32(GetLastError())) ); @@ -159,7 +159,7 @@ impl Application { // and an eventual error code exit for the process. for hwnd in &state.windows { if PostMessageW(*hwnd, DS_REQUEST_DESTROY, 0, 0) == FALSE { - log::warn!( + tracing::warn!( "PostMessageW DS_REQUEST_DESTROY failed: {}", Error::Hr(HRESULT_FROM_WIN32(GetLastError())) ); @@ -172,7 +172,7 @@ impl Application { } } } else { - log::warn!("Application state already borrowed"); + tracing::warn!("Application state already borrowed"); } } diff --git a/druid-shell/src/platform/windows/clipboard.rs b/druid-shell/src/platform/windows/clipboard.rs index 9a041d06eb..4c4bfb05b2 100644 --- a/druid-shell/src/platform/windows/clipboard.rs +++ b/druid-shell/src/platform/windows/clipboard.rs @@ -53,13 +53,16 @@ impl Clipboard { let format_id = match get_format_id(&format.identifier) { Some(id) => id, None => { - log::warn!("failed to register clipboard format {}", &format.identifier); + tracing::warn!( + "failed to register clipboard format {}", + &format.identifier + ); continue; } }; let result = SetClipboardData(format_id, handle); if result.is_null() { - log::warn!( + tracing::warn!( "failed to set clipboard for fmt {}, error: {}", &format.identifier, GetLastError() @@ -116,7 +119,7 @@ impl Clipboard { let format_id = match get_format_id(&format) { Some(id) => id, None => { - log::warn!("failed to register clipboard format {}", &format); + tracing::warn!("failed to register clipboard format {}", &format); return None; } }; @@ -196,7 +199,7 @@ fn register_identifier(ident: &str) -> Option { Ok(s) => s, Err(_) => { // granted this should happen _never_, but unwrap feels bad - log::warn!("Null byte in clipboard identifier '{}'", ident); + tracing::warn!("Null byte in clipboard identifier '{}'", ident); return None; } }; @@ -204,7 +207,7 @@ fn register_identifier(ident: &str) -> Option { let pb_format = RegisterClipboardFormatA(cstr.as_ptr()); if pb_format == 0 { let err = GetLastError(); - log::warn!( + tracing::warn!( "failed to register clipboard format '{}'; error {}.", ident, err @@ -236,7 +239,10 @@ fn iter_clipboard_types() -> impl Iterator { match GetLastError() { ERROR_SUCCESS => (), other => { - log::error!("iterating clipboard formats failed, error={}", other) + tracing::error!( + "iterating clipboard formats failed, error={}", + other + ) } } None @@ -273,7 +279,7 @@ fn get_format_name(format: UINT) -> String { if err == 87 { String::from("Unknown Format") } else { - log::warn!( + tracing::warn!( "error getting clipboard format name for format {}, errno {}", format, err diff --git a/druid-shell/src/platform/windows/dcomp.rs b/druid-shell/src/platform/windows/dcomp.rs index ddc9a36cb2..9a57de325f 100644 --- a/druid-shell/src/platform/windows/dcomp.rs +++ b/druid-shell/src/platform/windows/dcomp.rs @@ -19,7 +19,7 @@ use std::ptr::{null, null_mut}; -use log::error; +use tracing::error; use winapi::shared::winerror::SUCCEEDED; use winapi::um::d3d11::*; diff --git a/druid-shell/src/platform/windows/dialog.rs b/druid-shell/src/platform/windows/dialog.rs index f68d0eb29e..caf8378480 100644 --- a/druid-shell/src/platform/windows/dialog.rs +++ b/druid-shell/src/platform/windows/dialog.rs @@ -157,7 +157,7 @@ pub(crate) unsafe fn get_file_dialog_path( &IShellItem::uuidof(), &mut item as *mut *mut IShellItem as *mut *mut c_void, )) { - log::warn!("Failed to convert path: {}", err.to_string()); + tracing::warn!("Failed to convert path: {}", err.to_string()); } else { as_result(file_dialog.SetDefaultFolder(item))?; } diff --git a/druid-shell/src/platform/windows/keycodes.rs b/druid-shell/src/platform/windows/keycodes.rs index c72162a50e..d4420c24e8 100644 --- a/druid-shell/src/platform/windows/keycodes.rs +++ b/druid-shell/src/platform/windows/keycodes.rs @@ -214,6 +214,7 @@ map_keys! { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; #[test] fn win_vk() { diff --git a/druid-shell/src/platform/windows/menu.rs b/druid-shell/src/platform/windows/menu.rs index ce748ffbde..507b9a9734 100644 --- a/druid-shell/src/platform/windows/menu.rs +++ b/druid-shell/src/platform/windows/menu.rs @@ -176,7 +176,7 @@ fn convert_hotkey(id: u32, key: &HotKey) -> Option { } vk_code & 0x00ff } else { - log::error!("Failed to convert key {:?} into virtual key code", key.key); + tracing::error!("Failed to convert key {:?} into virtual key code", key.key); return None; }; diff --git a/druid-shell/src/platform/windows/screen.rs b/druid-shell/src/platform/windows/screen.rs index f5b23ca421..67da1c9f01 100644 --- a/druid-shell/src/platform/windows/screen.rs +++ b/druid-shell/src/platform/windows/screen.rs @@ -15,9 +15,9 @@ //! Windows Monitors and Screen information. use super::error::Error; -use log::warn; use std::mem::size_of; use std::ptr::null_mut; +use tracing::warn; use winapi::shared::minwindef::*; use winapi::shared::windef::*; use winapi::shared::winerror::*; diff --git a/druid-shell/src/platform/windows/util.rs b/druid-shell/src/platform/windows/util.rs index 4107c2bc1b..a5d72b7a7a 100644 --- a/druid-shell/src/platform/windows/util.rs +++ b/druid-shell/src/platform/windows/util.rs @@ -174,7 +174,7 @@ fn load_optional_functions() -> OptionalFunctions { let function_ptr = unsafe { GetProcAddress($lib, cstr.as_ptr()) }; if function_ptr.is_null() { - log::info!( + tracing::info!( "Could not load `{}`. Windows {} or later is needed", name, $min_windows_version @@ -210,14 +210,14 @@ fn load_optional_functions() -> OptionalFunctions { let mut GetSystemMetricsForDpi = None; if shcore.is_null() { - log::info!("No shcore.dll"); + tracing::info!("No shcore.dll"); } else { load_function!(shcore, SetProcessDpiAwareness, "8.1"); load_function!(shcore, GetDpiForMonitor, "8.1"); } if user32.is_null() { - log::info!("No user32.dll"); + tracing::info!("No user32.dll"); } else { load_function!(user32, GetDpiForSystem, "10"); load_function!(user32, GetDpiForWindow, "10"); diff --git a/druid-shell/src/platform/windows/window.rs b/druid-shell/src/platform/windows/window.rs index 1976493cff..6174539345 100644 --- a/druid-shell/src/platform/windows/window.rs +++ b/druid-shell/src/platform/windows/window.rs @@ -25,8 +25,8 @@ use std::rc::{Rc, Weak}; use std::sync::{Arc, Mutex}; use std::time::{Duration, Instant}; -use log::{debug, error, warn}; use scopeguard::defer; +use tracing::{debug, error, warn}; use winapi::ctypes::{c_int, c_void}; use winapi::shared::dxgi::*; use winapi::shared::dxgi1_2::*; @@ -433,7 +433,7 @@ impl MyWndProc { None } } else { - log::error!("failed to borrow WndState at {}", Location::caller()); + error!("failed to borrow WndState at {}", Location::caller()); None }; if ret.is_some() { @@ -864,7 +864,7 @@ impl WndProc for MyWndProc { } if SUCCEEDED(res) { if let Err(e) = s.rebuild_render_target(&self.d2d_factory, scale) { - log::error!("error building render target: {}", e); + error!("error building render target: {}", e); } s.render( &self.d2d_factory, @@ -946,7 +946,7 @@ impl WndProc for MyWndProc { }; unsafe { if ScreenToClient(hwnd, &mut p) == FALSE { - log::warn!( + warn!( "ScreenToClient failed: {}", Error::Hr(HRESULT_FROM_WIN32(GetLastError())) ); @@ -1042,7 +1042,7 @@ impl WndProc for MyWndProc { XBUTTON2 => Some(MouseButton::X2), w => { // Should never happen with current Windows - log::warn!("Received an unknown XBUTTON event ({})", w); + warn!("Received an unknown XBUTTON event ({})", w); None } } @@ -1218,7 +1218,7 @@ impl WindowBuilder { } pub fn set_level(&mut self, _level: WindowLevel) { - log::warn!("WindowBuilder::set_level is currently unimplemented for Windows platforms."); + warn!("WindowBuilder::set_level is currently unimplemented for Windows platforms."); } pub fn build(self) -> Result { @@ -1561,7 +1561,7 @@ impl WindowHandle { /// Bring this window to the front of the window stack and give it focus. pub fn bring_to_front_and_focus(&self) { //FIXME: implementation goes here - log::warn!("bring_to_front_and_focus not yet implemented on windows"); + warn!("bring_to_front_and_focus not yet implemented on windows"); } pub fn request_anim_frame(&self) { @@ -1572,7 +1572,7 @@ impl WindowHandle { // invalidating anything. We do this because we won't know the final invalidated region // until after calling prepare_paint. if RedrawWindow(hwnd, null(), null_mut(), RDW_INTERNALPAINT) == 0 { - log::warn!( + warn!( "RedrawWindow failed: {}", Error::Hr(HRESULT_FROM_WIN32(GetLastError())) ); @@ -1659,7 +1659,7 @@ impl WindowHandle { } pub fn content_insets(&self) -> Insets { - log::warn!("WindowHandle::content_insets unimplemented for windows."); + warn!("WindowHandle::content_insets unimplemented for windows."); Insets::ZERO } diff --git a/druid-shell/src/platform/x11/application.rs b/druid-shell/src/platform/x11/application.rs index 1d52202869..8cbc54aa1f 100644 --- a/druid-shell/src/platform/x11/application.rs +++ b/druid-shell/src/platform/x11/application.rs @@ -115,7 +115,7 @@ impl Application { match Application::query_present_opcode(&connection) { Ok(p) => p, Err(e) => { - log::info!("failed to find Present extension: {}", e); + tracing::info!("failed to find Present extension: {}", e); None } } @@ -152,7 +152,7 @@ impl Application { .present_query_version(1, 0)? .reply() .context("query Present version")?; - log::info!( + tracing::info!( "X server supports Present version {}.{}", version.major_version, version.minor_version, @@ -166,7 +166,7 @@ impl Application { .xfixes_query_version(5, 0)? .reply() .context("query XFIXES version")?; - log::info!( + tracing::info!( "X server supports XFIXES version {}.{}", version.major_version, version.minor_version, @@ -383,7 +383,7 @@ impl Application { .filter_map(|w| w.next_timeout()) .min() } else { - log::error!("Getting next timeout, application state already borrowed"); + tracing::error!("Getting next timeout, application state already borrowed"); None }; let next_idle_time = last_idle_time + timeout; @@ -413,7 +413,7 @@ impl Application { } } Err(e) => { - log::error!("Error handling event: {:#}", e); + tracing::error!("Error handling event: {:#}", e); } } event = self.connection.poll_for_event()?; @@ -427,7 +427,7 @@ impl Application { w.run_timers(now); } } else { - log::error!("In timer loop, application state already borrowed"); + tracing::error!("In timer loop, application state already borrowed"); } } } @@ -440,7 +440,7 @@ impl Application { w.run_idle(); } } else { - log::error!("In idle loop, application state already borrowed"); + tracing::error!("In idle loop, application state already borrowed"); } } } @@ -448,7 +448,7 @@ impl Application { pub fn run(self, _handler: Option>) { if let Err(e) = self.run_inner() { - log::error!("{}", e); + tracing::error!("{}", e); } } @@ -468,29 +468,29 @@ impl Application { } } } else { - log::error!("Application state already borrowed"); + tracing::error!("Application state already borrowed"); } } fn finalize_quit(&self) { log_x11!(self.connection.destroy_window(self.window_id)); if let Err(e) = nix::unistd::close(self.idle_read) { - log::error!("Error closing idle_read: {}", e); + tracing::error!("Error closing idle_read: {}", e); } if let Err(e) = nix::unistd::close(self.idle_write) { - log::error!("Error closing idle_write: {}", e); + tracing::error!("Error closing idle_write: {}", e); } } pub fn clipboard(&self) -> Clipboard { // TODO(x11/clipboard): implement Application::clipboard - log::warn!("Application::clipboard is currently unimplemented for X11 platforms."); + tracing::warn!("Application::clipboard is currently unimplemented for X11 platforms."); Clipboard {} } pub fn get_locale() -> String { // TODO(x11/locales): implement Application::get_locale - log::warn!("Application::get_locale is currently unimplemented for X11 platforms. (defaulting to en-US)"); + tracing::warn!("Application::get_locale is currently unimplemented for X11 platforms. (defaulting to en-US)"); "en-US".into() } diff --git a/druid-shell/src/platform/x11/clipboard.rs b/druid-shell/src/platform/x11/clipboard.rs index 240a99ac41..88fcc4e9bf 100644 --- a/druid-shell/src/platform/x11/clipboard.rs +++ b/druid-shell/src/platform/x11/clipboard.rs @@ -15,6 +15,7 @@ //! Interactions with the system pasteboard on X11. use crate::clipboard::{ClipboardFormat, FormatId}; +use tracing::warn; #[derive(Debug, Clone, Default)] pub struct Clipboard; @@ -22,35 +23,35 @@ pub struct Clipboard; impl Clipboard { pub fn put_string(&mut self, _s: impl AsRef) { // TODO(x11/clipboard): implement Clipboard::put_string - log::warn!("Clipboard::put_string is currently unimplemented for X11 platforms."); + warn!("Clipboard::put_string is currently unimplemented for X11 platforms."); } pub fn put_formats(&mut self, _formats: &[ClipboardFormat]) { // TODO(x11/clipboard): implement Clipboard::put_formats - log::warn!("Clipboard::put_formats is currently unimplemented for X11 platforms."); + warn!("Clipboard::put_formats is currently unimplemented for X11 platforms."); } pub fn get_string(&self) -> Option { // TODO(x11/clipboard): implement Clipboard::get_string - log::warn!("Clipboard::set_string is currently unimplemented for X11 platforms."); + warn!("Clipboard::set_string is currently unimplemented for X11 platforms."); None } pub fn preferred_format(&self, _formats: &[FormatId]) -> Option { // TODO(x11/clipboard): implement Clipboard::preferred_format - log::warn!("Clipboard::preferred_format is currently unimplemented for X11 platforms."); + warn!("Clipboard::preferred_format is currently unimplemented for X11 platforms."); None } pub fn get_format(&self, _format: FormatId) -> Option> { // TODO(x11/clipboard): implement Clipboard::get_format - log::warn!("Clipboard::get_format is currently unimplemented for X11 platforms."); + warn!("Clipboard::get_format is currently unimplemented for X11 platforms."); None } pub fn available_type_names(&self) -> Vec { // TODO(x11/clipboard): implement Clipboard::available_type_names - log::warn!("Clipboard::available_type_names is currently unimplemented for X11 platforms."); + warn!("Clipboard::available_type_names is currently unimplemented for X11 platforms."); vec![] } } diff --git a/druid-shell/src/platform/x11/menu.rs b/druid-shell/src/platform/x11/menu.rs index 210153ec11..dd30876a60 100644 --- a/druid-shell/src/platform/x11/menu.rs +++ b/druid-shell/src/platform/x11/menu.rs @@ -21,19 +21,19 @@ pub struct Menu; impl Menu { pub fn new() -> Menu { // TODO(x11/menus): implement Menu::new (currently a no-op) - log::warn!("Menu::new is currently unimplemented for X11 platforms."); + tracing::warn!("Menu::new is currently unimplemented for X11 platforms."); Menu {} } pub fn new_for_popup() -> Menu { // TODO(x11/menus): implement Menu::new_for_popup (currently a no-op) - log::warn!("Menu::new_for_popup is currently unimplemented for X11 platforms."); + tracing::warn!("Menu::new_for_popup is currently unimplemented for X11 platforms."); Menu {} } pub fn add_dropdown(&mut self, mut _menu: Menu, _text: &str, _enabled: bool) { // TODO(x11/menus): implement Menu::add_dropdown (currently a no-op) - log::warn!("Menu::add_dropdown is currently unimplemented for X11 platforms."); + tracing::warn!("Menu::add_dropdown is currently unimplemented for X11 platforms."); } pub fn add_item( @@ -45,11 +45,11 @@ impl Menu { _selected: bool, ) { // TODO(x11/menus): implement Menu::add_item (currently a no-op) - log::warn!("Menu::add_item is currently unimplemented for X11 platforms."); + tracing::warn!("Menu::add_item is currently unimplemented for X11 platforms."); } pub fn add_separator(&mut self) { // TODO(x11/menus): implement Menu::add_separator (currently a no-op) - log::warn!("Menu::add_separator is currently unimplemented for X11 platforms."); + tracing::warn!("Menu::add_separator is currently unimplemented for X11 platforms."); } } diff --git a/druid-shell/src/platform/x11/screen.rs b/druid-shell/src/platform/x11/screen.rs index 843b267714..c52bc4006b 100644 --- a/druid-shell/src/platform/x11/screen.rs +++ b/druid-shell/src/platform/x11/screen.rs @@ -17,6 +17,6 @@ use crate::screen::Monitor; pub(crate) fn get_monitors() -> Vec { - log::warn!("Screen::get_monitors() is currently unimplemented for X11 platforms."); + tracing::warn!("Screen::get_monitors() is currently unimplemented for X11 platforms."); Vec::new() } diff --git a/druid-shell/src/platform/x11/util.rs b/druid-shell/src/platform/x11/util.rs index 9c2714ed95..2e57d2e640 100644 --- a/druid-shell/src/platform/x11/util.rs +++ b/druid-shell/src/platform/x11/util.rs @@ -61,7 +61,7 @@ pub fn refresh_rate(conn: &Rc, window_id: Window) -> Option match try_refresh_rate() { Err(e) => { - log::error!("failed to find refresh rate: {}", e); + tracing::error!("failed to find refresh rate: {}", e); None } Ok(r) => Some(r), @@ -87,7 +87,7 @@ macro_rules! log_x11 { // a context where X11 errors probably just mean that the connection to the X server // was lost. In particular, it doesn't represent a druid-shell bug for which we want // more context. - log::error!("X11 error: {}", e); + tracing::error!("X11 error: {}", e); } }; } diff --git a/druid-shell/src/platform/x11/window.rs b/druid-shell/src/platform/x11/window.rs index 87f7a1e0a0..9c19d72d75 100644 --- a/druid-shell/src/platform/x11/window.rs +++ b/druid-shell/src/platform/x11/window.rs @@ -26,6 +26,7 @@ use std::time::Instant; use anyhow::{anyhow, Context, Error}; use cairo::{XCBConnection as CairoXCBConnection, XCBDrawable, XCBSurface, XCBVisualType}; +use tracing::{error, info, warn}; use x11rb::atom_manager; use x11rb::connection::Connection; use x11rb::protocol::present::{CompleteNotifyEvent, ConnectionExt as _, IdleNotifyEvent}; @@ -120,28 +121,28 @@ impl WindowBuilder { } pub fn set_min_size(&mut self, min_size: Size) { - log::warn!("WindowBuilder::set_min_size is implemented, but the setting is currently unused for X11 platforms."); + warn!("WindowBuilder::set_min_size is implemented, but the setting is currently unused for X11 platforms."); self.min_size = min_size; } pub fn resizable(&mut self, _resizable: bool) { - log::warn!("WindowBuilder::resizable is currently unimplemented for X11 platforms."); + warn!("WindowBuilder::resizable is currently unimplemented for X11 platforms."); } pub fn show_titlebar(&mut self, _show_titlebar: bool) { - log::warn!("WindowBuilder::show_titlebar is currently unimplemented for X11 platforms."); + warn!("WindowBuilder::show_titlebar is currently unimplemented for X11 platforms."); } pub fn set_position(&mut self, _position: Point) { - log::warn!("WindowBuilder::set_position is currently unimplemented for X11 platforms."); + warn!("WindowBuilder::set_position is currently unimplemented for X11 platforms."); } pub fn set_level(&mut self, _level: window::WindowLevel) { - log::warn!("WindowBuilder::set_level is currently unimplemented for X11 platforms."); + warn!("WindowBuilder::set_level is currently unimplemented for X11 platforms."); } pub fn set_window_state(&self, _state: window::WindowState) { - log::warn!("WindowBuilder::set_window_state is currently unimplemented for X11 platforms."); + warn!("WindowBuilder::set_window_state is currently unimplemented for X11 platforms."); } pub fn set_title>(&mut self, title: S) { @@ -277,7 +278,7 @@ impl WindowBuilder { let present_data = match self.initialize_present_data(id) { Ok(p) => Some(p), Err(e) => { - log::info!("Failed to initialize present extension: {}", e); + info!("Failed to initialize present extension: {}", e); None } }; @@ -550,7 +551,7 @@ impl Window { || self.present_data.try_borrow_mut().is_err() || self.buffers.try_borrow_mut().is_err() { - log::error!("other RefCells were borrowed when calling into the handler"); + error!("other RefCells were borrowed when calling into the handler"); return None; } @@ -565,7 +566,7 @@ impl Window { match self.handler.try_borrow_mut() { Ok(mut h) => Some(f(&mut **h)), Err(_) => { - log::error!("failed to borrow WinHandler at {}", Location::caller()); + error!("failed to borrow WinHandler at {}", Location::caller()); None } } @@ -586,7 +587,7 @@ impl Window { if !self.destroyed() { match borrow_mut!(self.state) { Ok(mut state) => state.destroyed = true, - Err(e) => log::error!("Failed to set destroyed flag: {}", e), + Err(e) => error!("Failed to set destroyed flag: {}", e), } log_x11!(self.app.connection().destroy_window(self.id)); } @@ -639,7 +640,7 @@ impl Window { let pixmap = if let Some(p) = buffers.idle_pixmaps.last() { *p } else { - log::info!("ran out of idle pixmaps, creating a new one"); + info!("ran out of idle pixmaps, creating a new one"); buffers.create_pixmap(self.app.connection(), self.id)? }; @@ -734,12 +735,12 @@ impl Window { /// Set whether the window should be resizable fn resizable(&self, _resizable: bool) { - log::warn!("Window::resizeable is currently unimplemented for X11 platforms."); + warn!("Window::resizeable is currently unimplemented for X11 platforms."); } /// Set whether the window should show titlebar fn show_titlebar(&self, _show_titlebar: bool) { - log::warn!("Window::show_titlebar is currently unimplemented for X11 platforms."); + warn!("Window::show_titlebar is currently unimplemented for X11 platforms."); } /// Bring this window to the front of the window stack and give it focus. @@ -784,7 +785,7 @@ impl Window { fn request_anim_frame(&self) { if let Ok(true) = self.waiting_on_present() { if let Err(e) = self.set_needs_present(true) { - log::error!( + error!( "Window::request_anim_frame - failed to schedule present: {}", e ); @@ -801,13 +802,13 @@ impl Window { fn invalidate(&self) { match self.size() { Ok(size) => self.invalidate_rect(size.to_rect()), - Err(err) => log::error!("Window::invalidate - failed to get size: {}", err), + Err(err) => error!("Window::invalidate - failed to get size: {}", err), } } fn invalidate_rect(&self, rect: Rect) { if let Err(err) = self.add_invalid_rect(rect) { - log::error!("Window::invalidate_rect - failed to enlarge rect: {}", err); + error!("Window::invalidate_rect - failed to enlarge rect: {}", err); } self.request_anim_frame(); @@ -984,23 +985,22 @@ impl Window { // one present request in flight, so we should only get notified about the request // that we're waiting for. if present.waiting_on != Some(event.serial) { - log::warn!( + warn!( "Got a notify for serial {}, but waiting on {:?}", - event.serial, - present.waiting_on + event.serial, present.waiting_on ); } // Check whether we missed presenting on any frames. if let Some(last_msc) = present.last_msc { if last_msc.wrapping_add(1) != event.msc { - log::debug!( + tracing::debug!( "missed a present: msc went from {} to {}", last_msc, event.msc ); if let Some(last_ust) = present.last_ust { - log::debug!("ust went from {} to {}", last_ust, event.ust); + tracing::debug!("ust went from {} to {}", last_ust, event.ust); } } } @@ -1082,7 +1082,7 @@ impl Window { if needs_redraw { if let Err(e) = self.redraw_now() { - log::error!("Error redrawing: {}", e); + error!("Error redrawing: {}", e); } } } @@ -1255,7 +1255,7 @@ fn mouse_button(button: u8) -> MouseButton { 8 => MouseButton::X1, 9 => MouseButton::X2, _ => { - log::warn!("unknown mouse button code {}", button); + warn!("unknown mouse button code {}", button); MouseButton::None } } @@ -1324,7 +1324,7 @@ impl IdleHandle { Err(nix::Error::Sys(nix::errno::Errno::EINTR)) => {} Err(nix::Error::Sys(nix::errno::Errno::EAGAIN)) => {} Err(e) => { - log::error!("Failed to write to idle pipe: {}", e); + error!("Failed to write to idle pipe: {}", e); break; } Ok(_) => { @@ -1371,7 +1371,7 @@ impl WindowHandle { if let Some(w) = self.window.upgrade() { w.show(); } else { - log::error!("Window {} has already been dropped", self.id); + error!("Window {} has already been dropped", self.id); } } @@ -1379,7 +1379,7 @@ impl WindowHandle { if let Some(w) = self.window.upgrade() { w.close(); } else { - log::error!("Window {} has already been dropped", self.id); + error!("Window {} has already been dropped", self.id); } } @@ -1387,7 +1387,7 @@ impl WindowHandle { if let Some(w) = self.window.upgrade() { w.resizable(resizable); } else { - log::error!("Window {} has already been dropped", self.id); + error!("Window {} has already been dropped", self.id); } } @@ -1395,55 +1395,55 @@ impl WindowHandle { if let Some(w) = self.window.upgrade() { w.show_titlebar(show_titlebar); } else { - log::error!("Window {} has already been dropped", self.id); + error!("Window {} has already been dropped", self.id); } } pub fn set_position(&self, _position: Point) { - log::warn!("WindowHandle::set_position is currently unimplemented for X11 platforms."); + warn!("WindowHandle::set_position is currently unimplemented for X11 platforms."); } pub fn get_position(&self) -> Point { - log::warn!("WindowHandle::get_position is currently unimplemented for X11 platforms."); + warn!("WindowHandle::get_position is currently unimplemented for X11 platforms."); Point::new(0.0, 0.0) } pub fn content_insets(&self) -> Insets { - log::warn!("WindowHandle::content_insets unimplemented for X11 platforms."); + warn!("WindowHandle::content_insets unimplemented for X11 platforms."); Insets::ZERO } pub fn set_level(&self, _level: WindowLevel) { - log::warn!("WindowHandle::set_level is currently unimplemented for X11 platforms."); + warn!("WindowHandle::set_level is currently unimplemented for X11 platforms."); } pub fn set_size(&self, _size: Size) { - log::warn!("WindowHandle::set_size is currently unimplemented for X11 platforms."); + warn!("WindowHandle::set_size is currently unimplemented for X11 platforms."); } pub fn get_size(&self) -> Size { - log::warn!("WindowHandle::get_size is currently unimplemented for X11 platforms."); + warn!("WindowHandle::get_size is currently unimplemented for X11 platforms."); Size::new(0.0, 0.0) } pub fn set_window_state(&self, _state: window::WindowState) { - log::warn!("WindowHandle::set_window_state is currently unimplemented for X11 platforms."); + warn!("WindowHandle::set_window_state is currently unimplemented for X11 platforms."); } pub fn get_window_state(&self) -> window::WindowState { - log::warn!("WindowHandle::get_window_state is currently unimplemented for X11 platforms."); + warn!("WindowHandle::get_window_state is currently unimplemented for X11 platforms."); window::WindowState::RESTORED } pub fn handle_titlebar(&self, _val: bool) { - log::warn!("WindowHandle::handle_titlebar is currently unimplemented for X11 platforms."); + warn!("WindowHandle::handle_titlebar is currently unimplemented for X11 platforms."); } pub fn bring_to_front_and_focus(&self) { if let Some(w) = self.window.upgrade() { w.bring_to_front_and_focus(); } else { - log::error!("Window {} has already been dropped", self.id); + error!("Window {} has already been dropped", self.id); } } @@ -1451,7 +1451,7 @@ impl WindowHandle { if let Some(w) = self.window.upgrade() { w.request_anim_frame(); } else { - log::error!("Window {} has already been dropped", self.id); + error!("Window {} has already been dropped", self.id); } } @@ -1459,7 +1459,7 @@ impl WindowHandle { if let Some(w) = self.window.upgrade() { w.invalidate(); } else { - log::error!("Window {} has already been dropped", self.id); + error!("Window {} has already been dropped", self.id); } } @@ -1467,7 +1467,7 @@ impl WindowHandle { if let Some(w) = self.window.upgrade() { w.invalidate_rect(rect); } else { - log::error!("Window {} has already been dropped", self.id); + error!("Window {} has already been dropped", self.id); } } @@ -1475,7 +1475,7 @@ impl WindowHandle { if let Some(w) = self.window.upgrade() { w.set_title(title); } else { - log::error!("Window {} has already been dropped", self.id); + error!("Window {} has already been dropped", self.id); } } @@ -1483,7 +1483,7 @@ impl WindowHandle { if let Some(w) = self.window.upgrade() { w.set_menu(menu); } else { - log::error!("Window {} has already been dropped", self.id); + error!("Window {} has already been dropped", self.id); } } @@ -1506,25 +1506,25 @@ impl WindowHandle { } pub fn make_cursor(&self, _cursor_desc: &CursorDesc) -> Option { - log::warn!("Custom cursors are not yet supported in the X11 backend"); + warn!("Custom cursors are not yet supported in the X11 backend"); None } pub fn open_file(&mut self, _options: FileDialogOptions) -> Option { // TODO(x11/file_dialogs): implement WindowHandle::open_file - log::warn!("WindowHandle::open_file is currently unimplemented for X11 platforms."); + warn!("WindowHandle::open_file is currently unimplemented for X11 platforms."); None } pub fn save_as(&mut self, _options: FileDialogOptions) -> Option { // TODO(x11/file_dialogs): implement WindowHandle::save_as - log::warn!("WindowHandle::save_as is currently unimplemented for X11 platforms."); + warn!("WindowHandle::save_as is currently unimplemented for X11 platforms."); None } pub fn show_context_menu(&self, _menu: Menu, _pos: Point) { // TODO(x11/menus): implement WindowHandle::show_context_menu - log::warn!("WindowHandle::show_context_menu is currently unimplemented for X11 platforms."); + warn!("WindowHandle::show_context_menu is currently unimplemented for X11 platforms."); } pub fn get_idle_handle(&self) -> Option { @@ -1542,7 +1542,7 @@ impl WindowHandle { if let Some(w) = self.window.upgrade() { Ok(w.get_scale()?) } else { - log::error!("Window {} has already been dropped", self.id); + error!("Window {} has already been dropped", self.id); Ok(Scale::new(1.0, 1.0)) } } diff --git a/druid-shell/src/util.rs b/druid-shell/src/util.rs index e5df06b2cf..c3dab2aaeb 100644 --- a/druid-shell/src/util.rs +++ b/druid-shell/src/util.rs @@ -55,7 +55,9 @@ pub fn claim_main_thread() { match old_thread_id { Ok(0) => (), Ok(_) => unreachable!(), // not possible per the docs - Err(0) => log::warn!("The main thread status was already claimed by the current thread."), + Err(0) => { + tracing::warn!("The main thread status was already claimed by the current thread.") + } Err(k) => panic!( "The main thread status has already been claimed by thread {}", k @@ -75,7 +77,7 @@ pub fn release_main_thread() { match old_thread_id { Ok(n) if n == thread_id => (), Ok(_) => unreachable!(), // not possible per the docs - Err(0) => log::warn!("The main thread status was already vacant."), + Err(0) => tracing::warn!("The main thread status was already vacant."), Err(k) => panic!( "The main thread status has already been claimed by thread {}", k diff --git a/druid/Cargo.toml b/druid/Cargo.toml index 03b1d83c86..c7131f9f85 100644 --- a/druid/Cargo.toml +++ b/druid/Cargo.toml @@ -53,7 +53,9 @@ druid-shell = { version = "0.7.0", default-features = false, path = "../druid-sh druid-derive = { version = "0.4.0", path = "../druid-derive" } log = "0.4.11" +tracing = { version = "0.1.22", features = ["log"] } simple_logger = { version = "1.9.0", default-features = false } +tracing-subscriber = { version = "0.2.15" } fluent-bundle = "0.12.0" fluent-langneg = "0.13.0" fluent-syntax = "0.9.3" @@ -71,7 +73,9 @@ usvg = { version = "0.12.0", optional = true } harfbuzz-sys = { version = "0.4.0", optional = true } [target.'cfg(target_arch="wasm32")'.dependencies] -console_log = "0.2.0" +console_log = { version = "0.2.0" } +tracing-wasm = { version = "0.1.0" } +console_error_panic_hook = { version = "0.1.6" } [dev-dependencies] float-cmp = { version = "0.8.0", features = ["std"], default-features = false } @@ -79,6 +83,7 @@ float-cmp = { version = "0.8.0", features = ["std"], default-features = false } tempfile = "=3.1.0" piet-common = { version = "=0.3.2", features = ["png"] } pulldown-cmark = { version = "0.8", default-features = false } +test-env-log = { version = "0.2.5", features = ["trace"], default-features = false } [[example]] name = "cursor" diff --git a/druid/examples/anim.rs b/druid/examples/anim.rs index c90912eb68..e340f09f21 100644 --- a/druid/examples/anim.rs +++ b/druid/examples/anim.rs @@ -86,7 +86,7 @@ pub fn main() { .with_placeholder("You spin me right round..."), ); AppLauncher::with_window(window) - .use_simple_logger() + .use_env_tracing() .launch(()) .expect("launch failed"); } diff --git a/druid/examples/async_event.rs b/druid/examples/async_event.rs index a260f0ea5f..670340beea 100644 --- a/druid/examples/async_event.rs +++ b/druid/examples/async_event.rs @@ -48,7 +48,7 @@ pub fn main() { thread::spawn(move || generate_colors(event_sink)); launcher - .use_simple_logger() + .use_env_tracing() .launch(Color::BLACK) .expect("launch failed"); } diff --git a/druid/examples/calc.rs b/druid/examples/calc.rs index d8db3e48fe..aced11009e 100644 --- a/druid/examples/calc.rs +++ b/druid/examples/calc.rs @@ -256,7 +256,7 @@ pub fn main() { in_num: false, }; AppLauncher::with_window(window) - .use_simple_logger() + .use_env_tracing() .launch(calc_state) .expect("launch failed"); } diff --git a/druid/examples/cursor.rs b/druid/examples/cursor.rs index eeef4fb7b5..af42c0d1d6 100644 --- a/druid/examples/cursor.rs +++ b/druid/examples/cursor.rs @@ -119,7 +119,7 @@ pub fn main() { custom_desc, }; AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(data) .expect("launch failed"); } diff --git a/druid/examples/custom_widget.rs b/druid/examples/custom_widget.rs index 6b9009ded2..142799f1c0 100644 --- a/druid/examples/custom_widget.rs +++ b/druid/examples/custom_widget.rs @@ -153,7 +153,7 @@ impl Widget for CustomWidget { pub fn main() { let window = WindowDesc::new(CustomWidget {}).title(LocalizedString::new("Fancy Colors")); AppLauncher::with_window(window) - .use_simple_logger() + .use_env_tracing() .launch("Druid + Piet".to_string()) .expect("launch failed"); } diff --git a/druid/examples/either.rs b/druid/examples/either.rs index 1eb5072fa7..d860f0d17f 100644 --- a/druid/examples/either.rs +++ b/druid/examples/either.rs @@ -47,7 +47,7 @@ fn ui_builder() -> impl Widget { pub fn main() { let main_window = WindowDesc::new(ui_builder()).title("Switcheroo"); AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(AppState::default()) .expect("launch failed"); } diff --git a/druid/examples/event_viewer.rs b/druid/examples/event_viewer.rs index 773a32192c..46f5aa4368 100644 --- a/druid/examples/event_viewer.rs +++ b/druid/examples/event_viewer.rs @@ -333,7 +333,7 @@ pub fn main() { //start the application AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .configure_env(|env, _| { env.set(theme::UI_FONT, FontDescriptor::default().with_size(12.0)); env.set(theme::LABEL_COLOR, TEXT_COLOR); diff --git a/druid/examples/flex.rs b/druid/examples/flex.rs index d332272fce..6af5c67426 100644 --- a/druid/examples/flex.rs +++ b/druid/examples/flex.rs @@ -341,7 +341,7 @@ pub fn main() { }; AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(AppState { demo_state, params }) .expect("Failed to launch application"); } diff --git a/druid/examples/game_of_life.rs b/druid/examples/game_of_life.rs index 9e0334b1a8..a1a2827e90 100644 --- a/druid/examples/game_of_life.rs +++ b/druid/examples/game_of_life.rs @@ -434,7 +434,7 @@ pub fn main() { } AppLauncher::with_window(window) - .use_simple_logger() + .use_env_tracing() .launch(AppData { grid, drawing: false, diff --git a/druid/examples/hello.rs b/druid/examples/hello.rs index a807f5b12a..67b2c3bb0f 100644 --- a/druid/examples/hello.rs +++ b/druid/examples/hello.rs @@ -40,7 +40,7 @@ pub fn main() { // start the application. Here we pass in the application state. AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(initial_state) .expect("Failed to launch application"); } diff --git a/druid/examples/identity.rs b/druid/examples/identity.rs index a9cc0e7d56..1191c60101 100644 --- a/druid/examples/identity.rs +++ b/druid/examples/identity.rs @@ -46,7 +46,7 @@ pub fn main() { counter_two: 0, }; AppLauncher::with_window(window) - .use_simple_logger() + .use_env_tracing() .launch(data) .expect("launch failed"); } diff --git a/druid/examples/image.rs b/druid/examples/image.rs index 210e9183ce..3fafb62e11 100644 --- a/druid/examples/image.rs +++ b/druid/examples/image.rs @@ -219,7 +219,7 @@ pub fn main() { }; AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(state) .expect("Failed to launch application"); } diff --git a/druid/examples/invalidation.rs b/druid/examples/invalidation.rs index 788ed438f2..92b2ef5929 100644 --- a/druid/examples/invalidation.rs +++ b/druid/examples/invalidation.rs @@ -32,7 +32,7 @@ pub fn main() { circles: Vector::new(), }; AppLauncher::with_window(window) - .use_simple_logger() + .use_env_tracing() .launch(state) .expect("launch failed"); } diff --git a/druid/examples/layout.rs b/druid/examples/layout.rs index 0d1ab57d93..07cb18ad19 100644 --- a/druid/examples/layout.rs +++ b/druid/examples/layout.rs @@ -69,7 +69,7 @@ pub fn main() { let window = WindowDesc::new(build_app()).title("Very flexible"); AppLauncher::with_window(window) - .use_simple_logger() + .use_env_tracing() .launch(0) .expect("launch failed"); } diff --git a/druid/examples/list.rs b/druid/examples/list.rs index 83feed6f7a..8c9f80aa9c 100644 --- a/druid/examples/list.rs +++ b/druid/examples/list.rs @@ -42,7 +42,7 @@ pub fn main() { right, }; AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(data) .expect("launch failed"); } diff --git a/druid/examples/markdown_preview.rs b/druid/examples/markdown_preview.rs index 29d2137bbb..442b5c66d5 100644 --- a/druid/examples/markdown_preview.rs +++ b/druid/examples/markdown_preview.rs @@ -77,7 +77,7 @@ pub fn main() { // start the application AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(initial_state) .expect("Failed to launch application"); } diff --git a/druid/examples/multiwin.rs b/druid/examples/multiwin.rs index 0ea1257aa7..22ae5102a8 100644 --- a/druid/examples/multiwin.rs +++ b/druid/examples/multiwin.rs @@ -24,7 +24,7 @@ use druid::{ DelegateCtx, Handled, LocalizedString, MenuDesc, MenuItem, Selector, Target, WindowDesc, WindowId, }; -use log::info; +use tracing::info; const MENU_COUNT_ACTION: Selector = Selector::new("menu-count-action"); const MENU_INCREMENT_ACTION: Selector = Selector::new("menu-increment-action"); @@ -48,7 +48,7 @@ pub fn main() { .delegate(Delegate { windows: Vec::new(), }) - .use_simple_logger() + .use_env_tracing() .launch(State::default()) .expect("launch failed"); } diff --git a/druid/examples/open_save.rs b/druid/examples/open_save.rs index 39320e41cf..dceb414826 100644 --- a/druid/examples/open_save.rs +++ b/druid/examples/open_save.rs @@ -28,7 +28,7 @@ pub fn main() { let data = "Type here.".to_owned(); AppLauncher::with_window(main_window) .delegate(Delegate) - .use_simple_logger() + .use_env_tracing() .launch(data) .expect("launch failed"); } diff --git a/druid/examples/panels.rs b/druid/examples/panels.rs index 0f703e2db0..80cdc0bb2d 100644 --- a/druid/examples/panels.rs +++ b/druid/examples/panels.rs @@ -95,7 +95,7 @@ pub fn main() -> Result<(), PlatformError> { let main_window = WindowDesc::new(build_app()) .title(LocalizedString::new("panels-demo-window-title").with_placeholder("Fancy Boxes!")); AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(())?; Ok(()) diff --git a/druid/examples/scroll.rs b/druid/examples/scroll.rs index 8be7d45397..cd6d932962 100644 --- a/druid/examples/scroll.rs +++ b/druid/examples/scroll.rs @@ -25,7 +25,7 @@ pub fn main() { let window = WindowDesc::new(build_widget()) .title(LocalizedString::new("scroll-demo-window-title").with_placeholder("Scroll demo")); AppLauncher::with_window(window) - .use_simple_logger() + .use_env_tracing() .launch(0u32) .expect("launch failed"); } diff --git a/druid/examples/scroll_colors.rs b/druid/examples/scroll_colors.rs index d84aa197c7..44a093b9a0 100644 --- a/druid/examples/scroll_colors.rs +++ b/druid/examples/scroll_colors.rs @@ -47,7 +47,7 @@ pub fn main() { ); let data = 0_u32; AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(data) .expect("launch failed"); } diff --git a/druid/examples/split_demo.rs b/druid/examples/split_demo.rs index ecbcf29412..83e29cb878 100644 --- a/druid/examples/split_demo.rs +++ b/druid/examples/split_demo.rs @@ -80,7 +80,7 @@ pub fn main() { let window = WindowDesc::new(build_app()) .title(LocalizedString::new("split-demo-window-title").with_placeholder("Split Demo")); AppLauncher::with_window(window) - .use_simple_logger() + .use_env_tracing() .launch(0u32) .expect("launch failed"); } diff --git a/druid/examples/styled_text.rs b/druid/examples/styled_text.rs index d8ca5795e8..eee374aff6 100644 --- a/druid/examples/styled_text.rs +++ b/druid/examples/styled_text.rs @@ -58,7 +58,7 @@ pub fn main() -> Result<(), PlatformError> { }; AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(data)?; Ok(()) diff --git a/druid/examples/sub_window.rs b/druid/examples/sub_window.rs index 7568662af4..7f307e28ed 100644 --- a/druid/examples/sub_window.rs +++ b/druid/examples/sub_window.rs @@ -60,7 +60,7 @@ pub fn main() { // start the application AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(initial_state) .expect("Failed to launch application"); } @@ -130,7 +130,7 @@ impl> Controller for TooltipController { ctx.set_handled(); if deadline > now { let wait_for = deadline - now; - log::info!("Waiting another {:?}", wait_for); + tracing::info!("Waiting another {:?}", wait_for); Some(TooltipState::Waiting { last_move: *last_move, timer_expire: deadline, @@ -161,7 +161,7 @@ impl> Controller for TooltipController { match event { Event::MouseMove(me) if !ctx.is_hot() => { // TODO another timer on leaving - log::info!("Sending close window for {:?}", win_id); + tracing::info!("Sending close window for {:?}", win_id); ctx.submit_command(CLOSE_WINDOW.to(*win_id)); Some(TooltipState::Waiting { last_move: now, @@ -225,7 +225,7 @@ impl> Controller for DragWindowController { let within_window_change = me.window_pos.to_vec2() - init_pos.to_vec2(); let old_pos = ctx.window().get_position(); let new_pos = old_pos + within_window_change; - log::info!( + tracing::info!( "Drag {:?} ", ( init_pos, diff --git a/druid/examples/svg.rs b/druid/examples/svg.rs index cb86b74358..fb1d3d9036 100644 --- a/druid/examples/svg.rs +++ b/druid/examples/svg.rs @@ -14,7 +14,7 @@ //! This example shows how to draw an SVG. -use log::error; +use tracing::error; use druid::{ widget::{FillStrat, Flex, Svg, SvgData, WidgetExt}, @@ -26,7 +26,7 @@ pub fn main() { .title(LocalizedString::new("svg-demo-window-title").with_placeholder("Rawr!")); let data = 0_u32; AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(data) .expect("launch failed"); } diff --git a/druid/examples/switches.rs b/druid/examples/switches.rs index 90a0168eda..12995cfc10 100644 --- a/druid/examples/switches.rs +++ b/druid/examples/switches.rs @@ -70,7 +70,7 @@ pub fn main() { let window = WindowDesc::new(build_widget()) .title(LocalizedString::new("switch-demo-window-title").with_placeholder("Switch Demo")); AppLauncher::with_window(window) - .use_simple_logger() + .use_env_tracing() .launch(DemoState { value: true, stepper_value: 1.0, diff --git a/druid/examples/tabs.rs b/druid/examples/tabs.rs index 76eacf4cbd..8815c5770e 100644 --- a/druid/examples/tabs.rs +++ b/druid/examples/tabs.rs @@ -43,7 +43,7 @@ impl DynamicTabData { fn remove_tab(&mut self, idx: usize) { if idx >= self.tab_labels.len() { - log::warn!("Attempt to remove non existent tab at index {}", idx) + tracing::warn!("Attempt to remove non existent tab at index {}", idx) } else { self.removed_tabs += 1; self.tab_labels.remove(idx); @@ -89,7 +89,7 @@ pub fn main() { // start the application AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(initial_state) .expect("Failed to launch application"); } diff --git a/druid/examples/text.rs b/druid/examples/text.rs index 2399086cc9..f12890163d 100644 --- a/druid/examples/text.rs +++ b/druid/examples/text.rs @@ -100,7 +100,7 @@ pub fn main() { // start the application AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(initial_state) .expect("Failed to launch application"); } diff --git a/druid/examples/timer.rs b/druid/examples/timer.rs index 1f93e9d677..a0a85fe265 100644 --- a/druid/examples/timer.rs +++ b/druid/examples/timer.rs @@ -125,7 +125,7 @@ pub fn main() { .title(LocalizedString::new("timer-demo-window-title").with_placeholder("Look at it go!")); AppLauncher::with_window(window) - .use_simple_logger() + .use_env_tracing() .launch(0u32) .expect("launch failed"); } diff --git a/druid/examples/value_formatting/src/main.rs b/druid/examples/value_formatting/src/main.rs index edc3f5507e..5b4a95769e 100644 --- a/druid/examples/value_formatting/src/main.rs +++ b/druid/examples/value_formatting/src/main.rs @@ -50,7 +50,7 @@ pub fn main() { }; AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(data) .expect("launch failed"); } diff --git a/druid/examples/view_switcher.rs b/druid/examples/view_switcher.rs index 069251c109..e8313a0867 100644 --- a/druid/examples/view_switcher.rs +++ b/druid/examples/view_switcher.rs @@ -30,7 +30,7 @@ pub fn main() { current_text: "Edit me!".to_string(), }; AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(data) .expect("launch failed"); } diff --git a/druid/examples/web/Cargo.toml b/druid/examples/web/Cargo.toml index 539efae35f..cb6dc1ec53 100644 --- a/druid/examples/web/Cargo.toml +++ b/druid/examples/web/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] druid = { path="../..", features = ["im", "image", "png"] } - +tracing = "0.1.22" wasm-bindgen = "0.2.67" console_error_panic_hook = "0.1.6" log = "0.4.11" diff --git a/druid/examples/widget_gallery.rs b/druid/examples/widget_gallery.rs index 0e8ee7bf9c..f76d641739 100644 --- a/druid/examples/widget_gallery.rs +++ b/druid/examples/widget_gallery.rs @@ -61,7 +61,7 @@ pub fn main() { editable_text: "edit me!".into(), }; AppLauncher::with_window(main_window) - .use_simple_logger() + .use_env_tracing() .launch(data) .expect("launch failed"); } diff --git a/druid/src/app.rs b/druid/src/app.rs index 536ff9a32b..3043d5ce85 100644 --- a/druid/src/app.rs +++ b/druid/src/app.rs @@ -146,20 +146,57 @@ impl AppLauncher { self } - /// Initialize a minimal logger for printing logs out to stderr. + /// Initialize a minimal logger with DEBUG max level for printing logs out to stderr. /// - /// Meant for use during development only. + /// This is meant for use during development only. /// /// # Panics /// /// Panics if the logger fails to initialize. + #[deprecated(since = "0.7.0", note = "Use use_env_tracing instead")] pub fn use_simple_logger(self) -> Self { #[cfg(not(target_arch = "wasm32"))] simple_logger::SimpleLogger::new() + .with_level(log::LevelFilter::Debug) .init() .expect("Failed to initialize logger."); #[cfg(target_arch = "wasm32")] - console_log::init_with_level(log::Level::Trace).expect("Failed to initialize logger."); + console_log::init_with_level(log::Level::Debug).expect("Failed to initialize logger."); + self + } + + /// Initialize a minimal tracing subscriber with DEBUG max level for printing logs out to + /// stderr, controlled by ENV variables. + /// + /// This is meant for quick-and-dirty debugging. If you want more serious trace handling, + /// it's probably better to implement it yourself. + /// + /// # Panics + /// + /// Panics if the subscriber fails to initialize. + pub fn use_env_tracing(self) -> Self { + #[cfg(not(target_arch = "wasm32"))] + { + use tracing_subscriber::prelude::*; + let fmt_layer = tracing_subscriber::fmt::layer().with_target(true); + let filter_layer = tracing_subscriber::EnvFilter::try_from_default_env() + .or_else(|_| tracing_subscriber::EnvFilter::try_new("debug")) + .expect("Failed to initialize tracing subscriber"); + + tracing_subscriber::registry() + .with(filter_layer) + .with(fmt_layer) + .init(); + } + // Note - tracing-wasm might not work in headless Node.js. Probably doesn't matter anyway, + // because wasm targets will virtually always be browsers. + #[cfg(target_arch = "wasm32")] + { + console_error_panic_hook::set_once(); + // tracing_wasm doesn't let us filter by level, but chrome/firefox devtools can + // already do that anyway + tracing_wasm::set_as_global_default(); + } self } diff --git a/druid/src/bloom.rs b/druid/src/bloom.rs index b1dea6c746..948daed966 100644 --- a/druid/src/bloom.rs +++ b/druid/src/bloom.rs @@ -130,6 +130,7 @@ impl Default for Bloom { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; #[test] fn very_good_test() { diff --git a/druid/src/box_constraints.rs b/druid/src/box_constraints.rs index 19dce05bcf..cc564c9196 100644 --- a/druid/src/box_constraints.rs +++ b/druid/src/box_constraints.rs @@ -131,16 +131,16 @@ impl BoxConstraints { && self.min.expand() == self.min && self.max.expand() == self.max) { - log::warn!("Bad BoxConstraints passed to {}:", name); - log::warn!("{:?}", self); + tracing::warn!("Bad BoxConstraints passed to {}:", name); + tracing::warn!("{:?}", self); } if self.min.width.is_infinite() { - log::warn!("Infinite minimum width constraint passed to {}:", name); + tracing::warn!("Infinite minimum width constraint passed to {}:", name); } if self.min.height.is_infinite() { - log::warn!("Infinite minimum height constraint passed to {}:", name); + tracing::warn!("Infinite minimum height constraint passed to {}:", name); } } @@ -275,6 +275,7 @@ impl BoxConstraints { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; fn bc(min_width: f64, min_height: f64, max_width: f64, max_height: f64) -> BoxConstraints { BoxConstraints::new( diff --git a/druid/src/command.rs b/druid/src/command.rs index 702bba2ac9..a61be887e2 100644 --- a/druid/src/command.rs +++ b/druid/src/command.rs @@ -641,6 +641,7 @@ impl std::fmt::Debug for Notification { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; #[test] fn get_payload() { diff --git a/druid/src/contexts.rs b/druid/src/contexts.rs index 7db5ddef22..32cc3dae26 100644 --- a/druid/src/contexts.rs +++ b/druid/src/contexts.rs @@ -559,7 +559,7 @@ impl EventCtx<'_, '_> { if self.is_focused() { self.widget_state.request_focus = Some(FocusChange::Next); } else { - log::warn!("focus_next can only be called by the currently focused widget"); + tracing::warn!("focus_next can only be called by the currently focused widget"); } } @@ -574,7 +574,7 @@ impl EventCtx<'_, '_> { if self.is_focused() { self.widget_state.request_focus = Some(FocusChange::Previous); } else { - log::warn!("focus_prev can only be called by the currently focused widget"); + tracing::warn!("focus_prev can only be called by the currently focused widget"); } } @@ -589,7 +589,7 @@ impl EventCtx<'_, '_> { if self.is_focused() { self.widget_state.request_focus = Some(FocusChange::Resign); } else { - log::warn!( + tracing::warn!( "resign_focus can only be called by the currently focused widget ({:?})", self.widget_id() ); @@ -765,14 +765,14 @@ impl PaintCtx<'_, '_, '_> { /// ``` pub fn with_save(&mut self, f: impl FnOnce(&mut PaintCtx)) { if let Err(e) = self.render_ctx.save() { - log::error!("Failed to save RenderContext: '{}'", e); + tracing::error!("Failed to save RenderContext: '{}'", e); return; } f(self); if let Err(e) = self.render_ctx.restore() { - log::error!("Failed to restore RenderContext: '{}'", e); + tracing::error!("Failed to restore RenderContext: '{}'", e); } } diff --git a/druid/src/core.rs b/druid/src/core.rs index 0af0a10479..c1c1343f1c 100644 --- a/druid/src/core.rs +++ b/druid/src/core.rs @@ -226,7 +226,7 @@ impl> WidgetPod { /// [`set_origin`]: WidgetPod::set_origin pub fn set_layout_rect(&mut self, ctx: &mut LayoutCtx, data: &T, env: &Env, layout_rect: Rect) { if layout_rect.size() != self.state.size { - log::warn!("set_layout_rect passed different size than returned by layout method"); + tracing::warn!("set_layout_rect passed different size than returned by layout method"); } self.set_origin(ctx, data, env, layout_rect.origin()); } @@ -282,7 +282,7 @@ impl> WidgetPod { /// be set by the parent widget whenever it modifies the position of its child /// while painting it and propagating events. As a rule of thumb, you need this /// if and only if you `Affine::translate` the paint context before painting - /// your child. For an example, see the implentation of [`Scroll`]. + /// your child. For an example, see the implementation of [`Scroll`]. /// /// [`Scroll`]: widget/struct.Scroll.html pub fn set_viewport_offset(&mut self, offset: Vec2) { @@ -571,11 +571,11 @@ impl> WidgetPod { fn log_layout_issues(&self, size: Size) { if size.width.is_infinite() { let name = self.widget().type_name(); - log::warn!("Widget `{}` has an infinite width.", name); + tracing::warn!("Widget `{}` has an infinite width.", name); } if size.height.is_infinite() { let name = self.widget().type_name(); - log::warn!("Widget `{}` has an infinite height.", name); + tracing::warn!("Widget `{}` has an infinite height.", name); } } @@ -615,7 +615,7 @@ impl> WidgetPod { // log if we seem not to be laid out when we should be if self.state.is_expecting_set_origin_call && !event.should_propagate_to_hidden() { - log::warn!( + tracing::warn!( "{:?} received an event ({:?}) without having been laid out. \ This likely indicates a missed call to set_layout_rect.", ctx.widget_id(), @@ -861,7 +861,7 @@ impl> WidgetPod { } if !inner_ctx.notifications.is_empty() { - log::warn!( + tracing::warn!( "A Notification was submitted while handling another \ notification; the submitted notification will be ignored." ); @@ -1212,6 +1212,7 @@ mod tests { use crate::text::format::ParseFormatter; use crate::widget::{Flex, Scroll, Split, TextBox}; use crate::{WidgetExt, WindowHandle, WindowId}; + use test_env_log::test; const ID_1: WidgetId = WidgetId::reserved(0); const ID_2: WidgetId = WidgetId::reserved(1); diff --git a/druid/src/data.rs b/druid/src/data.rs index 2a2f16f4f6..e5235f8cb3 100644 --- a/druid/src/data.rs +++ b/druid/src/data.rs @@ -594,6 +594,7 @@ impl_data_for_array! { 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 } #[cfg(test)] mod test { use super::Data; + use test_env_log::test; #[test] fn array_data() { diff --git a/druid/src/env.rs b/druid/src/env.rs index 4920e54b00..9bb69da77b 100644 --- a/druid/src/env.rs +++ b/druid/src/env.rs @@ -621,6 +621,7 @@ impl From> for KeyOrValue { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; #[test] fn string_key_or_value() { diff --git a/druid/src/localization.rs b/druid/src/localization.rs index 5b3cfe1c95..9e9f60f4bd 100644 --- a/druid/src/localization.rs +++ b/druid/src/localization.rs @@ -38,7 +38,7 @@ use std::collections::HashMap; use std::sync::Arc; use std::{fs, io}; -use log::{debug, error, warn}; +use tracing::{debug, error, warn}; use crate::{Application, ArcStr, Env}; @@ -387,6 +387,8 @@ impl<'a, T: std::fmt::Display> std::fmt::Display for PrintLocales<'a, T> { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; + #[test] fn resolve() { let en_us: LanguageIdentifier = "en-US".parse().unwrap(); diff --git a/druid/src/menu.rs b/druid/src/menu.rs index b4d752cd51..be9398f7fb 100644 --- a/druid/src/menu.rs +++ b/druid/src/menu.rs @@ -255,7 +255,7 @@ impl MenuDesc { return None; // we want to explicitly handle all platforms; log if a platform is missing. - log::warn!("MenuDesc::platform_default is not implemented for this platform."); + tracing::warn!("MenuDesc::platform_default is not implemented for this platform."); None } diff --git a/druid/src/sub_window.rs b/druid/src/sub_window.rs index 68affc56f8..d7f13cbbf5 100644 --- a/druid/src/sub_window.rs +++ b/druid/src/sub_window.rs @@ -107,7 +107,7 @@ impl> Widget<()> for SubWindowHost { self.data = dc.deref().clone(); ctx.request_update(); } else { - log::warn!("Received a sub window parent to host command that could not be unwrapped. \ + tracing::warn!("Received a sub window parent to host command that could not be unwrapped. \ This could mean that the sub window you requested and the enclosing widget pod that you opened it from do not share a common data type. \ Make sure you have a widget pod between your requesting widget and any lenses." ) } diff --git a/druid/src/tests/harness.rs b/druid/src/tests/harness.rs index 2de34e7dba..c5a2cb9b1b 100644 --- a/druid/src/tests/harness.rs +++ b/druid/src/tests/harness.rs @@ -318,7 +318,7 @@ impl Drop for Harness<'_, T> { // We need to call finish even if a test assert failed if let Err(err) = self.piet.finish() { // We can't panic, because we might already be panicking - log::error!("piet finish failed: {}", err); + tracing::error!("piet finish failed: {}", err); } } } diff --git a/druid/src/tests/invalidation_tests.rs b/druid/src/tests/invalidation_tests.rs index 496d699381..c8ae89a085 100644 --- a/druid/src/tests/invalidation_tests.rs +++ b/druid/src/tests/invalidation_tests.rs @@ -15,6 +15,7 @@ //! Tests related to propagation of invalid rects. use float_cmp::approx_eq; +use test_env_log::test; use super::*; diff --git a/druid/src/tests/layout_tests.rs b/druid/src/tests/layout_tests.rs index a4841124eb..6e3fe4b4a9 100644 --- a/druid/src/tests/layout_tests.rs +++ b/druid/src/tests/layout_tests.rs @@ -15,6 +15,7 @@ //! Tests related to layout. use float_cmp::approx_eq; +use test_env_log::test; use super::*; diff --git a/druid/src/text/attribute.rs b/druid/src/text/attribute.rs index 089a00c710..bd3dff827a 100644 --- a/druid/src/text/attribute.rs +++ b/druid/src/text/attribute.rs @@ -324,6 +324,7 @@ impl Default for SpanSet { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; #[test] fn smoke_test_spans() { diff --git a/druid/src/text/editable_text.rs b/druid/src/text/editable_text.rs index 2af6dd5ecd..7f09345d83 100644 --- a/druid/src/text/editable_text.rs +++ b/druid/src/text/editable_text.rs @@ -372,6 +372,7 @@ pub fn len_utf8_from_first_byte(b: u8) -> usize { mod tests { use super::*; use crate::Data; + use test_env_log::test; #[test] fn replace() { diff --git a/druid/src/text/editor.rs b/druid/src/text/editor.rs index e12a575cf3..ee9284785d 100644 --- a/druid/src/text/editor.rs +++ b/druid/src/text/editor.rs @@ -189,7 +189,7 @@ impl Editor { /// Perform an [`EditAction`](enum.EditAction.html). pub fn do_edit(&mut self, edit: EditAction, data: &mut T) { if self.data_is_stale(data) { - log::warn!("editor data changed externally, skipping event {:?}", &edit); + tracing::warn!("editor data changed externally, skipping event {:?}", &edit); return; } match edit { @@ -301,6 +301,7 @@ impl Default for Editor { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; /// Devanagari codepoints are 3 utf-8 code units each. #[test] diff --git a/druid/src/util.rs b/druid/src/util.rs index 31b5aa270e..9a4d281cd5 100644 --- a/druid/src/util.rs +++ b/druid/src/util.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; use std::hash::Hash; use std::mem; -/// Panic in debug and log::error in release mode. +/// Panic in debug and tracing::error in release mode. /// /// This macro is in some way a combination of `panic` and `debug_assert`, /// but it will log the provided message instead of ignoring it in release builds. @@ -30,7 +30,7 @@ macro_rules! debug_panic { if cfg!(debug_assertions) { panic!($msg); } else { - log::error!($msg); + tracing::error!($msg); } }; ($msg:expr,) => { debug_panic!($msg) }; @@ -38,7 +38,7 @@ macro_rules! debug_panic { if cfg!(debug_assertions) { panic!($fmt, $($arg)*); } else { - log::error!($fmt, $($arg)*); + tracing::error!($fmt, $($arg)*); } }; } diff --git a/druid/src/widget/align.rs b/druid/src/widget/align.rs index 5528b0e19d..dc5707218a 100644 --- a/druid/src/widget/align.rs +++ b/druid/src/widget/align.rs @@ -132,10 +132,10 @@ impl Widget for Align { fn log_size_warnings(size: Size) { if size.width.is_infinite() { - log::warn!("Align widget's child has an infinite width."); + tracing::warn!("Align widget's child has an infinite width."); } if size.height.is_infinite() { - log::warn!("Align widget's child has an infinite height."); + tracing::warn!("Align widget's child has an infinite height."); } } diff --git a/druid/src/widget/clip_box.rs b/druid/src/widget/clip_box.rs index 6ff6225d69..c99fac00aa 100644 --- a/druid/src/widget/clip_box.rs +++ b/druid/src/widget/clip_box.rs @@ -335,6 +335,8 @@ impl> Widget for ClipBox { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; + #[test] fn pan_to_visible() { let mut viewport = Viewport { diff --git a/druid/src/widget/flex.rs b/druid/src/widget/flex.rs index 2044a123aa..1ee41ef776 100644 --- a/druid/src/widget/flex.rs +++ b/druid/src/widget/flex.rs @@ -644,11 +644,11 @@ impl Widget for Flex { let baseline_offset = child.widget.baseline_offset(); if child_size.width.is_infinite() { - log::warn!("A non-Flex child has an infinite width."); + tracing::warn!("A non-Flex child has an infinite width."); } if child_size.height.is_infinite() { - log::warn!("A non-Flex child has an infinite height."); + tracing::warn!("A non-Flex child has an infinite height."); } major_non_flex += self.direction.major(child_size).expand(); @@ -740,7 +740,7 @@ impl Widget for Flex { } if flex_sum > 0.0 && total_major.is_infinite() { - log::warn!("A child of Flex is flex, but Flex is unbounded.") + tracing::warn!("A child of Flex is flex, but Flex is unbounded.") } if flex_sum > 0.0 { @@ -930,6 +930,7 @@ impl From for FlexParams { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; #[test] #[allow(clippy::cognitive_complexity)] diff --git a/druid/src/widget/image.rs b/druid/src/widget/image.rs index 5f5b616e58..d949ae94e2 100644 --- a/druid/src/widget/image.rs +++ b/druid/src/widget/image.rs @@ -243,9 +243,9 @@ impl Widget for Image { #[cfg(not(target_arch = "wasm32"))] #[cfg(test)] mod tests { - use crate::piet::ImageFormat; - use super::*; + use crate::piet::ImageFormat; + use test_env_log::test; /// Painting an empty image shouldn't crash druid. #[test] diff --git a/druid/src/widget/label.rs b/druid/src/widget/label.rs index 15c7d92b27..c77bcfe7c5 100644 --- a/druid/src/widget/label.rs +++ b/druid/src/widget/label.rs @@ -504,7 +504,7 @@ impl Widget for Label { fn paint(&mut self, ctx: &mut PaintCtx, _data: &T, env: &Env) { if self.text_should_be_updated { - log::warn!("Label text changed without call to update. See LabelAdapter::set_text for information."); + tracing::warn!("Label text changed without call to update. See LabelAdapter::set_text for information."); } self.label.paint(ctx, &self.current_text, env) } diff --git a/druid/src/widget/scroll.rs b/druid/src/widget/scroll.rs index cda2d14c57..f172dc6140 100644 --- a/druid/src/widget/scroll.rs +++ b/druid/src/widget/scroll.rs @@ -170,10 +170,10 @@ impl> Widget for Scroll { fn log_size_warnings(size: Size) { if size.width.is_infinite() { - log::warn!("Scroll widget's child has an infinite width."); + tracing::warn!("Scroll widget's child has an infinite width."); } if size.height.is_infinite() { - log::warn!("Scroll widget's child has an infinite height."); + tracing::warn!("Scroll widget's child has an infinite height."); } } diff --git a/druid/src/widget/sized_box.rs b/druid/src/widget/sized_box.rs index 493f2876a0..5047159ab3 100644 --- a/druid/src/widget/sized_box.rs +++ b/druid/src/widget/sized_box.rs @@ -160,11 +160,11 @@ impl Widget for SizedBox { }; if size.width.is_infinite() { - log::warn!("SizedBox is returning an infinite width."); + tracing::warn!("SizedBox is returning an infinite width."); } if size.height.is_infinite() { - log::warn!("SizedBox is returning an infinite height."); + tracing::warn!("SizedBox is returning an infinite height."); } size @@ -185,6 +185,7 @@ impl Widget for SizedBox { mod tests { use super::*; use crate::widget::Label; + use test_env_log::test; #[test] fn expand() { diff --git a/druid/src/widget/split.rs b/druid/src/widget/split.rs index 372d93ef83..7098a35477 100644 --- a/druid/src/widget/split.rs +++ b/druid/src/widget/split.rs @@ -337,12 +337,12 @@ impl Widget for Split { match self.split_axis { Axis::Horizontal => { if !bc.is_width_bounded() { - log::warn!("A Split widget was given an unbounded width to split.") + tracing::warn!("A Split widget was given an unbounded width to split.") } } Axis::Vertical => { if !bc.is_height_bounded() { - log::warn!("A Split widget was given an unbounded height to split.") + tracing::warn!("A Split widget was given an unbounded height to split.") } } } diff --git a/druid/src/widget/svg.rs b/druid/src/widget/svg.rs index 9aec614cad..0f90fde76f 100644 --- a/druid/src/widget/svg.rs +++ b/druid/src/widget/svg.rs @@ -146,7 +146,7 @@ impl SvgData { Rect::new(r.left(), r.top(), r.right(), r.bottom()) } _ => { - log::error!( + tracing::error!( "this SVG has no viewbox. It is expected that usvg always adds a viewbox" ); Rect::ZERO @@ -165,7 +165,9 @@ impl SvgData { Size::new(s.width(), s.height()) } _ => { - log::error!("this SVG has no size. It is expected that usvg always adds a size"); + tracing::error!( + "this SVG has no size. It is expected that usvg always adds a size" + ); Size::ZERO } }; @@ -221,7 +223,7 @@ impl SvgRenderer { usvg::NodeKind::LinearGradient(linear_gradient) => { self.linear_gradient_def(linear_gradient, ctx); } - other => log::error!("unsupported element: {:?}", other), + other => tracing::error!("unsupported element: {:?}", other), } } } @@ -234,7 +236,7 @@ impl SvgRenderer { } _ => { // TODO: handle more of the SVG spec. - log::error!("{:?} is unimplemented", n.clone()); + tracing::error!("{:?} is unimplemented", n.clone()); } } } @@ -367,6 +369,7 @@ fn color_from_svg(c: usvg::Color, opacity: usvg::Opacity) -> Color { #[cfg(test)] mod tests { use super::*; + use test_env_log::test; #[test] fn usvg_transform_vs_affine() { diff --git a/druid/src/widget/tabs.rs b/druid/src/widget/tabs.rs index 8ac412129f..ebc9e41949 100644 --- a/druid/src/widget/tabs.rs +++ b/druid/src/widget/tabs.rs @@ -911,7 +911,7 @@ impl Tabs { if let TabsContent::Building { tabs } = &mut self.content { TP::add_tab(tabs, name, child) } else { - log::warn!("Can't add static tabs to a running or complete tabs instance!") + tracing::warn!("Can't add static tabs to a running or complete tabs instance!") } } diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index c5afb3b755..8f59d204d2 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -768,7 +768,7 @@ impl Widget for ValueTextBox { .validate_partial_input(&new_text, &Selection::caret(0)) .is_err() { - log::warn!( + tracing::warn!( "formatter replacement text does not validate: '{}'", &new_text ); @@ -851,7 +851,7 @@ impl Widget for ValueTextBox { // editing, and new data arrives, we ignore the new data and keep // editing; the alternative would be to cancel editing, which // could also make sense. - log::warn!( + tracing::warn!( "ValueTextBox data changed externally, idk: '{}'", self.formatter.format(data) ); diff --git a/druid/src/widget/widget_ext.rs b/druid/src/widget/widget_ext.rs index acaf23f615..4aca8bc8bc 100644 --- a/druid/src/widget/widget_ext.rs +++ b/druid/src/widget/widget_ext.rs @@ -306,6 +306,7 @@ mod tests { use super::*; use crate::widget::Slider; use crate::Color; + use test_env_log::test; #[test] fn container_reuse() { diff --git a/druid/src/win_handler.rs b/druid/src/win_handler.rs index bcf0f9759e..9498c52963 100644 --- a/druid/src/win_handler.rs +++ b/druid/src/win_handler.rs @@ -110,7 +110,7 @@ impl Windows { let win = Window::new(id, handle, pending, ext_handle); assert!(self.windows.insert(id, win).is_none(), "duplicate window"); } else { - log::error!("no window for connecting handle {:?}", id); + tracing::error!("no window for connecting handle {:?}", id); } } @@ -404,7 +404,7 @@ impl Inner { } } Target::Auto => { - log::error!("{:?} reached window handler with `Target::Auto`", cmd); + tracing::error!("{:?} reached window handler with `Target::Auto`", cmd); } } Handled::No @@ -559,7 +559,7 @@ impl AppState { self.process_commands(); self.inner.borrow_mut().do_update(); } - other => log::warn!("unexpected idle token {:?}", other), + other => tracing::warn!("unexpected idle token {:?}", other), } } @@ -598,7 +598,7 @@ impl AppState { .borrow_mut() .append_command(cmd.default_to(default_target)) } - None => log::warn!("No command for menu id {}", cmd_id), + None => tracing::warn!("No command for menu id {}", cmd_id), } self.process_commands(); self.inner.borrow_mut().do_update(); @@ -615,12 +615,12 @@ impl AppState { _ if cmd.is(sys_cmd::HIDE_OTHERS) => self.hide_others(), _ if cmd.is(sys_cmd::NEW_WINDOW) => { if let Err(e) = self.new_window(cmd) { - log::error!("failed to create window: '{}'", e); + tracing::error!("failed to create window: '{}'", e); } } _ if cmd.is(sys_cmd::NEW_SUB_WINDOW) => { if let Err(e) = self.new_sub_window(cmd) { - log::error!("failed to create sub window: '{}'", e); + tracing::error!("failed to create sub window: '{}'", e); } } _ if cmd.is(sys_cmd::CLOSE_ALL_WINDOWS) => self.request_close_all_windows(), @@ -637,15 +637,15 @@ impl AppState { T::Window(id) if cmd.is(sys_cmd::SHOW_WINDOW) => self.show_window(id), T::Window(id) if cmd.is(sys_cmd::PASTE) => self.do_paste(id), _ if cmd.is(sys_cmd::CLOSE_WINDOW) => { - log::warn!("CLOSE_WINDOW command must target a window.") + tracing::warn!("CLOSE_WINDOW command must target a window.") } _ if cmd.is(sys_cmd::SHOW_WINDOW) => { - log::warn!("SHOW_WINDOW command must target a window.") + tracing::warn!("SHOW_WINDOW command must target a window.") } _ => { let handled = self.inner.borrow_mut().dispatch_cmd(cmd.clone()); if !handled.is_handled() && cmd.must_be_used() { - log::warn!("{:?} was not handled.", cmd); + tracing::warn!("{:?} was not handled.", cmd); } } } @@ -712,7 +712,7 @@ impl AppState { }; inner.append_command(cmd); } else { - log::error!("unknown dialog token"); + tracing::error!("unknown dialog token"); } std::mem::drop(inner); diff --git a/druid/src/window.rs b/druid/src/window.rs index 64a808e3fc..fc8bf134cf 100644 --- a/druid/src/window.rs +++ b/druid/src/window.rs @@ -165,7 +165,7 @@ impl Window { if let Some(mut handle) = self.handle.get_idle_handle() { handle.schedule_idle(RUN_COMMANDS_TOKEN); } else { - log::error!("failed to get idle handle"); + tracing::error!("failed to get idle handle"); } } } @@ -191,7 +191,7 @@ impl Window { if let Some(widget_id) = self.timers.get(&token) { Event::Internal(InternalEvent::RouteTimer(token, *widget_id)) } else { - log::error!("No widget found for timer {:?}", token); + tracing::error!("No widget found for timer {:?}", token); return Handled::No; } } @@ -223,9 +223,9 @@ impl Window { self.root.event(&mut ctx, &event, data, env); if !ctx.notifications.is_empty() { - log::info!("{} unhandled notifications:", ctx.notifications.len()); + tracing::info!("{} unhandled notifications:", ctx.notifications.len()); for (i, n) in ctx.notifications.iter().enumerate() { - log::info!("{}: {:?}", i, n); + tracing::info!("{}: {:?}", i, n); } } Handled::from(ctx.is_handled)