From f8d6c25032deca9cc8c39282b37174e468aa6b71 Mon Sep 17 00:00:00 2001 From: Filipe Rodrigues Date: Sat, 23 Aug 2025 03:03:12 +0100 Subject: [PATCH] Reworked many logging points. --- zsw-wgpu/src/lib.rs | 3 +- zsw-wgpu/src/renderer.rs | 18 ++++++++++-- zsw/src/config.rs | 4 +-- zsw/src/config_dirs.rs | 6 ++-- zsw/src/image_loader.rs | 54 +++++++++++++++++++++++++---------- zsw/src/init/logger.rs | 4 ++- zsw/src/main.rs | 12 ++++---- zsw/src/panel/images.rs | 6 +++- zsw/src/panel/panels.rs | 2 +- zsw/src/panel/renderer.rs | 4 +-- zsw/src/playlist/player.rs | 22 +++++++++++--- zsw/src/playlist/playlists.rs | 2 +- zsw/src/settings_menu.rs | 4 ++- zsw/src/window.rs | 2 +- 14 files changed, 101 insertions(+), 42 deletions(-) diff --git a/zsw-wgpu/src/lib.rs b/zsw-wgpu/src/lib.rs index faed6a6..85a53b6 100644 --- a/zsw-wgpu/src/lib.rs +++ b/zsw-wgpu/src/lib.rs @@ -75,7 +75,8 @@ async fn create_device(adapter: &wgpu::Adapter) -> Result<(wgpu::Device, wgpu::Q // Configure the device to not panic on errors device.on_uncaptured_error(Box::new(|err| { - tracing::error!("Wgpu error: {err}"); + let err = AppError::<()>::new(&err); + tracing::error!("Wgpu error: {}", err.pretty()); })); Ok((device, queue)) diff --git a/zsw-wgpu/src/renderer.rs b/zsw-wgpu/src/renderer.rs index 56e9594..4ed4399 100644 --- a/zsw-wgpu/src/renderer.rs +++ b/zsw-wgpu/src/renderer.rs @@ -78,7 +78,10 @@ impl WgpuRenderer { loop { match self.surface.get_current_texture() { Ok(surface_texture) => break surface_texture, - Err(err) => tracing::warn!(%err, "Unable to retrieve current texture, retrying"), + Err(err) => { + let err = AppError::<()>::new(&err); + tracing::warn!("Unable to retrieve current texture, retrying: {}", err.pretty()); + }, } } }); @@ -104,7 +107,11 @@ impl WgpuRenderer { /// Re-configures the surface pub fn reconfigure(&mut self, shared: &WgpuShared) -> Result<(), AppError> { - tracing::info!(size=?self.surface_size, "Reconfiguring wgpu surface"); + tracing::info!( + "Reconfiguring wgpu surface to {}x{}", + self.surface_size.width, + self.surface_size.height + ); // Update our surface self.surface_config = self::configure_window_surface(shared, &self.surface, self.surface_size) @@ -115,7 +122,12 @@ impl WgpuRenderer { /// Performs a resize pub fn resize(&mut self, shared: &WgpuShared, size: PhysicalSize) -> Result<(), AppError> { - tracing::info!(?size, "Resizing wgpu surface"); + tracing::info!( + "Resizing wgpu surface to {}x{}", + self.surface_size.width, + self.surface_size.height + ); + // TODO: Don't ignore resizes to the same size? if size.width > 0 && size.height > 0 && size != self.surface_size { // Update our surface diff --git a/zsw/src/config.rs b/zsw/src/config.rs index 2659dd0..5561cb2 100644 --- a/zsw/src/config.rs +++ b/zsw/src/config.rs @@ -56,7 +56,7 @@ impl Config { match Self::load(path) { Ok(config) => config, Err(err) => { - tracing::warn!("Unable to load config from {path:?}, using default: {err:?}"); + tracing::warn!("Unable to load config from {path:?}, using default: {}", err.pretty()); let config = Self::default(); // If the config file doesn't exist, write the default @@ -64,7 +64,7 @@ impl Config { if !fs::exists(path).unwrap_or(true) && let Err(err) = config.write(path) { - tracing::warn!("Unable to write default config to {path:?}: {err:?}"); + tracing::warn!("Unable to write default config to {path:?}: {}", err.pretty()); } config diff --git a/zsw/src/config_dirs.rs b/zsw/src/config_dirs.rs index e6e03bd..19b2871 100644 --- a/zsw/src/config_dirs.rs +++ b/zsw/src/config_dirs.rs @@ -37,7 +37,7 @@ impl ConfigDirs { pub fn panels(&self) -> &Path { self.panels.get_or_init(|| { let path = self.root.join("panels"); - tracing::info!(?path, "Panels path"); + tracing::info!("Panels path: {path:?}"); path }) } @@ -46,7 +46,7 @@ impl ConfigDirs { pub fn playlists(&self) -> &Path { self.playlists.get_or_init(|| { let path = self.root.join("playlists"); - tracing::info!(?path, "Playlists path"); + tracing::info!("Playlists path: {path:?}"); path }) } @@ -55,7 +55,7 @@ impl ConfigDirs { pub fn shaders(&self) -> &Path { self.shaders.get_or_init(|| { let path = self.root.join("shaders"); - tracing::info!(?path, "Shaders path"); + tracing::info!("Shaders path: {path:?}"); path }) } diff --git a/zsw/src/image_loader.rs b/zsw/src/image_loader.rs index c521bb0..5114263 100644 --- a/zsw/src/image_loader.rs +++ b/zsw/src/image_loader.rs @@ -130,11 +130,11 @@ impl ImageLoader { ) .await; if let Err(err) = &image_res { - tracing::warn!(?request, ?err, "Unable to load image"); + tracing::warn!("Unable to load image {:?}: {}", request.path, err.pretty()); } if let Err(response) = response_tx.send(ImageResponse { request, image_res }) { - tracing::warn!(?response.request, "Unable to send response to image request"); + tracing::warn!("Request for image {:?} was aborted", response.request.path); } }) .collect::<()>() @@ -166,18 +166,18 @@ impl ImageLoader { { Ok(Some(upscaled_image_path)) => image_path = upscaled_image_path, Ok(None) => (), - Err(err) => tracing::warn!(path = ?request.path, ?err, "Unable to upscale image"), + Err(err) => tracing::warn!("Unable to upscale image {:?}: {}", request.path, err.pretty()), } // Load the image - tracing::trace!(path = ?request.path, "Loading image"); + tracing::trace!("Loading image {:?}", request.path); let mut image = tokio::task::spawn_blocking(move || image::open(image_path)) .instrument(tracing::trace_span!("Loading image")) .await .context("Unable to join image load task")? .context("Unable to open image")?; - tracing::trace!(path = ?request.path, image_width = ?image.width(), image_height = ?image.height(), "Loaded image"); + tracing::trace!("Loaded image {:?} ({}x{})", request.path, image.width(), image.height()); // TODO: Use `request.geometries?` for upscaling? @@ -185,14 +185,24 @@ impl ImageLoader { if image.width() >= request.max_image_size || image.height() >= request.max_image_size { let max_image_size = request.max_image_size; - tracing::trace!(path = ?request.path, image_width = ?image.width(), image_height = ?image.height(), ?max_image_size, "Resizing image"); + tracing::trace!( + "Resizing image {:?} ({}x{}) to at most {max_image_size}x{max_image_size}", + request.path, + image.width(), + image.height() + ); image = tokio::task::spawn_blocking(move || { image.resize(max_image_size, max_image_size, image::imageops::FilterType::Nearest) }) .instrument(tracing::trace_span!("Resizing image")) .await .context("Failed to join image resize task")?; - tracing::trace!(path = ?request.path, image_width = ?image.width(), image_height = ?image.height(), "Resized image"); + tracing::trace!( + "Resized image {:?} to {}x{}", + request.path, + image.width(), + image.height() + ); } Ok(Image { @@ -219,7 +229,6 @@ impl ImageLoader { .await .context("Unable to join image check size task")? .context("Unable to get image size")?; - tracing::trace!(path = ?request.path, ?image_width, ?image_height, "Image size"); // Then compute the minimum size required. // Note: If none, we don't do anything else @@ -229,27 +238,36 @@ impl ImageLoader { .iter() .map(|size| Self::minimum_image_size_for_panel(Vector2::new(image_width, image_height), *size)) .reduce(|lhs, rhs| Vector2::new(lhs.x.max(rhs.x), lhs.y.max(rhs.y))); - tracing::trace!(?request, ?minimum_size, "Minimum image size"); let Some(minimum_size) = minimum_size else { + tracing::trace!( + "Image {:?} ({image_width}x{image_height}) had no minimum image size", + request.path, + ); return Ok(None); }; // If the image isn't smaller, return if image_width >= minimum_size.x && image_height >= minimum_size.y { + tracing::trace!( + "Image {:?} ({image_width}x{image_height}) is larger than smaller size {}x{}", + request.path, + minimum_size.x, + minimum_size.y + ); return Ok(None); } // If the image is in the excluded, return if upscale_exclude.contains(&request.path) { - tracing::trace!(path = ?request.path, "Not upscaling due to excluded"); + tracing::trace!("Not upscaling excluded image {:?}", request.path); return Ok(None); } // Else get the upscale command let Some(upscale_cmd) = upscale_cmd else { tracing::trace!( - path = ?request.path, - "Not upscaling due to no upscaler command supplied and none cached found" + "Not upscaling image {:?} due to no upscaler command supplied and no cached image found", + request.path ); return Ok(None); }; @@ -288,7 +306,13 @@ impl ImageLoader { ) .ceil() as u32; let ratio = ratio.next_power_of_two(); - tracing::trace!(?image_path, ?image_size, ?minimum_size, ?ratio, "Image upscaled ratio"); + tracing::trace!( + "Using upscale ratio x{ratio} for image {image_path:?} ({}x{}) with minimum size {}x{}", + image_size.x, + image_size.y, + minimum_size.x, + minimum_size.y + ); // Calculate the upscaled image path // TODO: Do this some other way? @@ -303,7 +327,7 @@ impl ImageLoader { } let _permit = upscale_semaphore.acquire().await; - tracing::trace!(?image_path, ?upscaled_image_path, ?ratio, "Upscaling image"); + tracing::trace!("Upscaling image {image_path:?} with scale x{ratio} to {upscaled_image_path:?}"); tokio::process::Command::new(upscale_cmd) .arg("-i") .arg(image_path) @@ -320,7 +344,7 @@ impl ImageLoader { .context("Unable to wait for upscaler to finish")? .exit_ok() .context("upscaler returned error")?; - tracing::trace!(?image_path, ?upscaled_image_path, "Upscaled image"); + tracing::trace!("Upscaled image {image_path:?} to {upscaled_image_path:?}"); Ok(upscaled_image_path) } diff --git a/zsw/src/init/logger.rs b/zsw/src/init/logger.rs index 69bff59..7c71191 100644 --- a/zsw/src/init/logger.rs +++ b/zsw/src/init/logger.rs @@ -13,6 +13,7 @@ use { }, tracing::{Dispatch, Subscriber, metadata::LevelFilter, subscriber::DefaultGuard}, tracing_subscriber::{EnvFilter, Layer, fmt::format::FmtSpan, prelude::*, registry::LookupSpan}, + zutil_app_error::AppError, }; /// Temporary subscriber type @@ -135,7 +136,8 @@ where file }, Err(err) => { - tracing::warn!("Unable to create log file {log_file:?}: {err}"); + let err = AppError::<()>::new(&err); + tracing::warn!("Unable to create log file {log_file:?}: {}", err.pretty()); return None; }, }; diff --git a/zsw/src/main.rs b/zsw/src/main.rs index 5865933..603c583 100644 --- a/zsw/src/main.rs +++ b/zsw/src/main.rs @@ -88,7 +88,7 @@ fn main() -> Result<(), AppError> { .to_path_buf(), ); let config_dirs = Arc::new(config_dirs); - tracing::debug!("config_path: {config_path:?}, config: {config:?}"); + tracing::debug!("Loaded config: {config:?}"); // Initialize the logger properly now logger.init_global(args.log_file.as_deref().or(config.log_file.as_deref())); @@ -159,7 +159,7 @@ impl winit::application::ApplicationHandler for WinitApp { ) { match self.event_tx.get(&window_id) { Some(event_tx) => _ = event_tx.send(event), - None => tracing::warn!(?window_id, ?event, "Received window event for unknown window"), + None => tracing::warn!("Received window event for unknown window {window_id:?}: {event:?}"), } } } @@ -360,17 +360,17 @@ async fn load_default_panel(default_panel: &config::ConfigPanel, shared: &Arc _ = entry.insert(panel_images), } - tracing::debug!(?panel_name, "Loaded default panel images"); + tracing::debug!("Loaded default panel images {panel_name:?}"); Ok(()) }); diff --git a/zsw/src/panel/images.rs b/zsw/src/panel/images.rs index a47134c..96b65ab 100644 --- a/zsw/src/panel/images.rs +++ b/zsw/src/panel/images.rs @@ -140,7 +140,11 @@ impl PanelImages { // Else, log an error, remove the image and re-schedule it Err(err) => { - tracing::warn!(image_path = ?response.request.path, ?err, "Unable to load image, removing it from player"); + tracing::warn!( + "Unable to load image {:?}, removing it from player: {}", + response.request.path, + err.pretty() + ); self.playlist_player.remove(&response.request.path); _ = self.schedule_load_image(wgpu_shared, image_requester, geometries).await; diff --git a/zsw/src/panel/panels.rs b/zsw/src/panel/panels.rs index 354a029..fb2dac0 100644 --- a/zsw/src/panel/panels.rs +++ b/zsw/src/panel/panels.rs @@ -50,7 +50,7 @@ impl Panels { .get_or_try_init(async move || { // Try to read the file let panel_path = self.path_of(&panel_name); - tracing::debug!(%panel_name, ?panel_path, "Loading panel"); + tracing::debug!("Loading panel {panel_name:?} from {panel_path:?}"); let panel_toml = tokio::fs::read_to_string(panel_path) .await .context("Unable to open file")?; diff --git a/zsw/src/panel/renderer.rs b/zsw/src/panel/renderer.rs index 4a2a680..6215c55 100644 --- a/zsw/src/panel/renderer.rs +++ b/zsw/src/panel/renderer.rs @@ -412,7 +412,7 @@ async fn create_render_pipeline( ) -> Result { let shader_path = config_dirs.shaders().join(shader.path()); - tracing::debug!(?shader, ?shader_path, "Creating render pipeline for shader"); + tracing::debug!("Creating render pipeline for shader {shader:?} from {shader_path:?}"); let shader_module = self::parse_shader(&shader_path, shader) .await @@ -562,7 +562,7 @@ fn parse_shader_module( } // Then add it as a module - tracing::debug!(?module_path, "Processing shader module"); + tracing::trace!("Processing shader {shader_dir:?} module {module_path:?}"); _ = composer .add_composable_module(ComposableModuleDescriptor { source: &module_source, diff --git a/zsw/src/playlist/player.rs b/zsw/src/playlist/player.rs index 870decc..37bd82c 100644 --- a/zsw/src/playlist/player.rs +++ b/zsw/src/playlist/player.rs @@ -12,6 +12,7 @@ use { }, tokio::{fs, sync::Mutex}, zsw_util::{UnwrapOrReturnExt, WalkDir}, + zutil_app_error::AppError, }; /// Playlist player @@ -64,7 +65,8 @@ impl PlaylistPlayer { let entry = match entry { Ok(entry) => entry, Err(err) => { - tracing::warn!(%err, "Unable to read directory entry"); + let err = AppError::<()>::new(&err); + tracing::warn!("Unable to read directory entry: {}", err.pretty()); return; }, }; @@ -72,7 +74,13 @@ impl PlaylistPlayer { let path = entry.path(); if fs::metadata(&path) .await - .map_err(|err| tracing::warn!(?path, ?err, "Unable to get playlist entry metadata")) + .map_err(|err| { + let err = AppError::<()>::new(&err); + tracing::warn!( + "Unable to get playlist entry {path:?} metadata: {}", + err.pretty() + ); + }) .unwrap_or_return()? .is_dir() { @@ -82,7 +90,10 @@ impl PlaylistPlayer { match tokio::fs::canonicalize(&path).await { Ok(entry) => _ = all_items.lock().await.insert(entry.into()), - Err(err) => tracing::warn!(?path, ?err, "Unable to read playlist entry"), + Err(err) => { + let err = AppError::<()>::new(&err); + tracing::warn!("Unable to read playlist entry {path:?}: {}", err.pretty()); + }, } }) .collect::>() @@ -92,7 +103,10 @@ impl PlaylistPlayer { PlaylistItemKind::File { ref path } => match tokio::fs::canonicalize(path).await { Ok(path) => _ = all_items.lock().await.insert(path.into()), - Err(err) => tracing::warn!(?path, ?err, "Unable to canonicalize playlist entry"), + Err(err) => { + let err = AppError::<()>::new(&err); + tracing::warn!("Unable to canonicalize playlist entry {path:?}: {}", err.pretty()); + }, }, } }) diff --git a/zsw/src/playlist/playlists.rs b/zsw/src/playlist/playlists.rs index c871fa2..2a88693 100644 --- a/zsw/src/playlist/playlists.rs +++ b/zsw/src/playlist/playlists.rs @@ -44,7 +44,7 @@ impl Playlists { .get_or_try_init(async move || { // Try to read the file let playlist_path = self.path_of(&playlist_name); - tracing::debug!(%playlist_name, ?playlist_path, "Loading playlist"); + tracing::debug!("Loading playlist {playlist_name:?} from {playlist_path:?}"); let playlist_toml = tokio::fs::read_to_string(playlist_path) .await .context("Unable to open file")?; diff --git a/zsw/src/settings_menu.rs b/zsw/src/settings_menu.rs index 519622f..12ec91c 100644 --- a/zsw/src/settings_menu.rs +++ b/zsw/src/settings_menu.rs @@ -13,6 +13,7 @@ use { egui::Widget, std::path::Path, zsw_util::{Rect, TokioTaskBlockOn}, + zutil_app_error::AppError, }; /// Settings menu @@ -246,7 +247,8 @@ fn draw_openable_path(ui: &mut egui::Ui, path: &Path) { if ui.link(path.to_string_lossy()).clicked() && let Err(err) = opener::open(path) { - tracing::warn!(?path, %err, "Unable to open file"); + let err = AppError::<()>::new(&err); + tracing::warn!("Unable to open file {path:?}: {}", err.pretty()); } }); } diff --git a/zsw/src/window.rs b/zsw/src/window.rs index cb8a458..fc7b93f 100644 --- a/zsw/src/window.rs +++ b/zsw/src/window.rs @@ -35,7 +35,7 @@ pub fn create(event_loop: &ActiveEventLoop) -> Result, AppError> .unwrap_or_else(|| format!("Monitor #{}", monitor_idx + 1)); let monitor_geometry = self::monitor_geometry(&monitor); - tracing::debug!(?monitor_name, ?monitor_geometry, "Found monitor geometry"); + tracing::debug!("Found monitor {monitor_name:?} geometry: {monitor_geometry}"); // Start building the window // TODO: `AlwaysOnBottom` doesn't work on wayland