Reworked many logging points.

This commit is contained in:
Filipe Rodrigues 2025-08-23 03:03:12 +01:00
parent 4c80f57577
commit f8d6c25032
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU
14 changed files with 101 additions and 42 deletions

View File

@ -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))

View File

@ -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<u32>) -> 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

View File

@ -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

View File

@ -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
})
}

View File

@ -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)
}

View File

@ -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;
},
};

View File

@ -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<AppEvent> 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<Sh
.load(panel_name.clone())
.await
.context("Unable to load panel")?;
tracing::debug!(%panel_name, "Loaded default panel");
tracing::debug!("Loaded default panel {panel_name:?}");
// Finally spawn a task to load the playlist player
#[cloned(shared)]
self::spawn_task(format!("Load playlist for {panel_name}"), async move {
self::spawn_task(format!("Load playlist for {panel_name:?}"), async move {
let playlist = shared
.playlists
.load(playlist_name.clone())
.await
.context("Unable to load playlist")?;
tracing::debug!(?playlist_name, "Loaded default playlist");
tracing::debug!("Loaded default playlist {playlist_name:?}");
let playlist_player = PlaylistPlayer::new(&playlist).await;
@ -380,7 +380,7 @@ async fn load_default_panel(default_panel: &config::ConfigPanel, shared: &Arc<Sh
tracing::warn!("Panel {panel_name:?} changed playlist before playlist {playlist_name:?} could load"),
hash_map::Entry::Vacant(entry) => _ = entry.insert(panel_images),
}
tracing::debug!(?panel_name, "Loaded default panel images");
tracing::debug!("Loaded default panel images {panel_name:?}");
Ok(())
});

View File

@ -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;

View File

@ -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")?;

View File

@ -412,7 +412,7 @@ async fn create_render_pipeline(
) -> Result<wgpu::RenderPipeline, AppError> {
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,

View File

@ -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::<FuturesUnordered<_>>()
@ -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());
},
},
}
})

View File

@ -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")?;

View File

@ -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());
}
});
}

View File

@ -35,7 +35,7 @@ pub fn create(event_loop: &ActiveEventLoop) -> Result<Vec<AppWindow>, 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