From df215da37238e3aae00254af6e2d6c28bf186961 Mon Sep 17 00:00:00 2001 From: psykose Date: Tue, 5 Nov 2024 11:38:34 +0100 Subject: [PATCH] more trace --- src/mpv/handle.rs | 13 ++++++++++--- src/ui/window.rs | 24 +++++++++++------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/mpv/handle.rs b/src/mpv/handle.rs index 1c0275d..48c87a7 100644 --- a/src/mpv/handle.rs +++ b/src/mpv/handle.rs @@ -57,7 +57,7 @@ impl Handle { // wraps via tracing later; note that info does nothing for now as it disables all logs #[cfg(debug_assertions)] - let loglevel = c"trace"; + let loglevel = c"debug"; #[cfg(not(debug_assertions))] let loglevel = c"info"; @@ -90,17 +90,24 @@ impl Handle { unsafe { ffi::mpv_client_id(self.inner.as_ptr()) } } - pub fn set_property(&self, name: &str, value: impl SetProperty) -> Result<(), Error> { + #[tracing::instrument(skip(self), parent = None, target = "mpv", name = "mpv_set_property", level = Level::DEBUG, fields(name = name, value = %value), ret)] + pub fn set_property( + &self, + name: &str, + value: impl SetProperty + fmt::Display, + ) -> Result<(), Error> { // need to add zero terminator let name = CString::new(name).expect("null bytes in property name"); unsafe { value.set_property(self.inner.as_ptr(), name.as_ptr()) } } - pub fn get_property(&self, name: &str) -> Result { + #[tracing::instrument(skip(self), parent = None, target = "mpv", name = "mpv_get_property", level = Level::DEBUG, fields(name = name), ret)] + pub fn get_property(&self, name: &str) -> Result { let name = CString::new(name).expect("null bytes in property name"); unsafe { T::get_property(self.inner.as_ptr(), name.as_ptr()) } } + #[tracing::instrument(skip(self, args), parent = None, target = "mpv", name = "mpv_command", level = Level::DEBUG)] pub fn command<'a>(&self, args: impl IntoIterator) -> Result<(), Error> { // add zero terminators to Everything let args: Vec = args diff --git a/src/ui/window.rs b/src/ui/window.rs index 3c21a97..a071a3c 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -144,9 +144,6 @@ mod imp { while let Some(event) = window.imp().mpv.wait_event(0.0) { use crate::mpv::Event; - let span = span!(Level::DEBUG, "mpv_wait_event"); - let _guard = span.enter(); - match event { Event::PropertyChange(event) => match event.reply_userdata { 0 => { @@ -223,31 +220,32 @@ mod imp { }, Event::LogMessage(event) => { + let span = span!(Level::DEBUG, "mpv_log", prefix = event.prefix); + let _guard = span.enter(); match event.log_level { // level has to be 'static so this sux l if l <= 20 => { - event!(target: "mpv", Level::ERROR, prefix = event.prefix, event = event.text.trim()) + event!(target: "mpv_event", Level::ERROR, "{}", event.text.trim()) } l if l <= 30 => { - event!(target: "mpv", Level::WARN, prefix = event.prefix, event = event.text.trim()) + event!(target: "mpv_event", Level::WARN, "{}", event.text.trim()) } l if l <= 40 => { - event!(target: "mpv", Level::INFO, prefix = event.prefix, event = event.text.trim()) + event!(target: "mpv_event", Level::INFO, "{}", event.text.trim()) } l if l <= 60 => { - event!(target: "mpv", Level::DEBUG, prefix = event.prefix, event = event.text.trim()) + event!(target: "mpv_event", Level::DEBUG, "{}", event.text.trim()) } l if l <= 70 => { - event!(target: "mpv", Level::TRACE, prefix = event.prefix, event = event.text.trim()) + event!(target: "mpv_event", Level::TRACE, "{}", event.text.trim()) } // should be unused _ => event!( - target: "mpv", + target: "mpv_erroneus_event", Level::DEBUG, - prefix = event.prefix, - event = event.text.trim(), - "unknown mpv level: {}", - event.log_level, + log_level = event.log_level, + "{}", + event.text.trim(), ), }; }