From 9b424587743896056f9230a90409f9c279014e48 Mon Sep 17 00:00:00 2001 From: Vladimir Romashchenko Date: Tue, 6 Aug 2024 19:11:57 -0400 Subject: [PATCH] Add tracing --- Cargo.lock | 1 + Cargo.toml | 1 + src/video_player.rs | 7 ++++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 14763f1..f3862f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1429,6 +1429,7 @@ dependencies = [ "iced_native", "iced_wgpu", "thiserror", + "tracing", "url", ] diff --git a/Cargo.toml b/Cargo.toml index b2cec3f..a8b0c41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ gstreamer = "0.22" gstreamer-app = "0.22" # appsink gstreamer-base = "0.22" # basesrc glib = "0.19" # gobject traits and error type +tracing = "0.1" # structured logging thiserror = "1" url = "2" # media uri diff --git a/src/video_player.rs b/src/video_player.rs index 8a9d120..c5348eb 100644 --- a/src/video_player.rs +++ b/src/video_player.rs @@ -7,6 +7,7 @@ use iced::{ use iced_wgpu::primitive::pipeline::Renderer as PrimitiveRenderer; use std::{marker::PhantomData, sync::atomic::Ordering}; use std::{sync::Arc, time::Duration}; +use tracing::error; /// Video player widget which displays the current frame of a [`Video`](crate::Video). pub struct VideoPlayer<'a, Message, Theme = iced::Theme, Renderer = iced::Renderer> @@ -121,6 +122,7 @@ where ); } + #[tracing::instrument(skip_all, fields(event = ?event))] fn on_event( &mut self, _state: &mut widget::Tree, @@ -147,10 +149,9 @@ where for msg in inner.bus.iter() { match msg.view() { gst::MessageView::Error(err) => { + error!("bus returned an error: {err}"); if let Some(ref on_error) = self.on_error { shell.publish(on_error(&err.error())) - } else { - panic!("{:#?}", err) }; } gst::MessageView::Eos(_eos) => { @@ -170,7 +171,7 @@ where // Don't run eos_pause if restart_stream is true; fixes "pausing" after restarting a stream if restart_stream { if let Err(err) = inner.restart_stream() { - eprintln!("cannot restart stream (can't seek): {:#?}", err); + error!("cannot restart stream (can't seek): {err:#?}") } } else if eos_pause { inner.is_eos = true;