mpv logge

This commit is contained in:
psykose 2024-11-04 22:00:17 +01:00
parent daff4e7dbd
commit 2c1eb852fd
2 changed files with 37 additions and 14 deletions

View file

@ -55,9 +55,14 @@ impl Handle {
); );
} }
// set up info logging for now // wraps via tracing later; note that info does nothing for now as it disables all logs
#[cfg(debug_assertions)]
let loglevel = c"trace";
#[cfg(not(debug_assertions))]
let loglevel = c"info";
Error::from_return_code(unsafe { Error::from_return_code(unsafe {
ffi::mpv_request_log_messages(inner.as_ptr(), c"info".as_ptr()) ffi::mpv_request_log_messages(inner.as_ptr(), loglevel.as_ptr())
}) })
.unwrap(); .unwrap();

View file

@ -7,7 +7,7 @@ mod imp {
use gtk::{gdk, gio, glib}; use gtk::{gdk, gio, glib};
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::rc::Rc; use std::rc::Rc;
use tracing::{event, Level}; use tracing::{event, span, Level};
#[derive(gtk::CompositeTemplate, glib::Properties)] #[derive(gtk::CompositeTemplate, glib::Properties)]
#[template(resource = "/eu/callcc/audrey/window.ui")] #[template(resource = "/eu/callcc/audrey/window.ui")]
@ -117,6 +117,9 @@ 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 => {
@ -164,17 +167,32 @@ mod imp {
}, },
Event::LogMessage(event) => { Event::LogMessage(event) => {
// TODO: levels etc match event.log_level {
if event.log_level < 30 { // level has to be 'static so this sux
event!(target: "mpv", Level::ERROR, "[{}] {}", event.prefix, event.text.trim()); l if l <= 20 => {
} else if event.log_level < 40 { event!(target: "mpv", Level::ERROR, prefix = event.prefix, event = event.text.trim())
event!(target: "mpv", Level::WARN, "[{}] {}", event.prefix, event.text.trim()); }
} else if event.log_level < 50 { l if l <= 30 => {
event!(target: "mpv", Level::INFO, "[{}] {}", event.prefix, event.text.trim()); event!(target: "mpv", Level::WARN, prefix = event.prefix, event = event.text.trim())
} else if event.log_level < 70 { }
event!(target: "mpv", Level::DEBUG, "[{}] {}", event.prefix, event.text.trim()); l if l <= 40 => {
} else { event!(target: "mpv", Level::INFO, prefix = event.prefix, event = event.text.trim())
event!(target: "mpv", Level::TRACE, "[{}] {}", event.prefix, event.text.trim()); }
l if l <= 60 => {
event!(target: "mpv", Level::DEBUG, prefix = event.prefix, event = event.text.trim())
}
l if l <= 70 => {
event!(target: "mpv", Level::TRACE, prefix = event.prefix, event = event.text.trim())
}
// should be unused
_ => event!(
target: "mpv",
Level::DEBUG,
prefix = event.prefix,
event = event.text.trim(),
"unknown mpv level: {}",
event.log_level,
),
}; };
} }