more trace

This commit is contained in:
psykose 2024-11-05 11:38:34 +01:00
parent 50a5b9323c
commit df215da372
2 changed files with 21 additions and 16 deletions

View file

@ -57,7 +57,7 @@ impl Handle {
// wraps via tracing later; note that info does nothing for now as it disables all logs // wraps via tracing later; note that info does nothing for now as it disables all logs
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
let loglevel = c"trace"; let loglevel = c"debug";
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
let loglevel = c"info"; let loglevel = c"info";
@ -90,17 +90,24 @@ impl Handle {
unsafe { ffi::mpv_client_id(self.inner.as_ptr()) } 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 // need to add zero terminator
let name = CString::new(name).expect("null bytes in property name"); let name = CString::new(name).expect("null bytes in property name");
unsafe { value.set_property(self.inner.as_ptr(), name.as_ptr()) } unsafe { value.set_property(self.inner.as_ptr(), name.as_ptr()) }
} }
pub fn get_property<T: GetProperty>(&self, name: &str) -> Result<T, Error> { #[tracing::instrument(skip(self), parent = None, target = "mpv", name = "mpv_get_property", level = Level::DEBUG, fields(name = name), ret)]
pub fn get_property<T: GetProperty + std::fmt::Debug>(&self, name: &str) -> Result<T, Error> {
let name = CString::new(name).expect("null bytes in property name"); let name = CString::new(name).expect("null bytes in property name");
unsafe { T::get_property(self.inner.as_ptr(), name.as_ptr()) } 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<Item = &'a str>) -> Result<(), Error> { pub fn command<'a>(&self, args: impl IntoIterator<Item = &'a str>) -> Result<(), Error> {
// add zero terminators to Everything // add zero terminators to Everything
let args: Vec<CString> = args let args: Vec<CString> = args

View file

@ -144,9 +144,6 @@ mod imp {
while let Some(event) = window.imp().mpv.wait_event(0.0) { while let Some(event) = window.imp().mpv.wait_event(0.0) {
use crate::mpv::Event; use crate::mpv::Event;
let span = span!(Level::DEBUG, "mpv_wait_event");
let _guard = span.enter();
match event { match event {
Event::PropertyChange(event) => match event.reply_userdata { Event::PropertyChange(event) => match event.reply_userdata {
0 => { 0 => {
@ -223,31 +220,32 @@ mod imp {
}, },
Event::LogMessage(event) => { Event::LogMessage(event) => {
let span = span!(Level::DEBUG, "mpv_log", prefix = event.prefix);
let _guard = span.enter();
match event.log_level { match event.log_level {
// level has to be 'static so this sux // level has to be 'static so this sux
l if l <= 20 => { 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 => { 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 => { 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 => { 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 => { 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 // should be unused
_ => event!( _ => event!(
target: "mpv", target: "mpv_erroneus_event",
Level::DEBUG, Level::DEBUG,
prefix = event.prefix, log_level = event.log_level,
event = event.text.trim(), "{}",
"unknown mpv level: {}", event.text.trim(),
event.log_level,
), ),
}; };
} }