From f18c41345768b3b19ffb0b235f54593548973a5e Mon Sep 17 00:00:00 2001 From: Erica Z Date: Mon, 4 Nov 2024 13:52:33 +0100 Subject: [PATCH] mpv logging --- src/mpv/event.rs | 2 +- src/mpv/handle.rs | 1 + src/ui/window.rs | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/mpv/event.rs b/src/mpv/event.rs index de3e768..4234999 100644 --- a/src/mpv/event.rs +++ b/src/mpv/event.rs @@ -48,7 +48,7 @@ pub struct LogMessageEvent { pub prefix: String, pub level: String, pub text: String, - //log_level: i32, + pub log_level: u32, } #[derive(Clone, Debug)] diff --git a/src/mpv/handle.rs b/src/mpv/handle.rs index bb9e65a..e8a48c5 100644 --- a/src/mpv/handle.rs +++ b/src/mpv/handle.rs @@ -188,6 +188,7 @@ impl Handle { text: unsafe { CStr::from_ptr(data.text) } .to_string_lossy() .into(), + log_level: data.log_level, })) } diff --git a/src/ui/window.rs b/src/ui/window.rs index 78d1138..7011290 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -169,6 +169,21 @@ mod imp { _ => unreachable!(), }, + Event::LogMessage(event) => { + // TODO: levels etc + if event.log_level < 30 { + event!(target: "mpv", Level::ERROR, "[{}] {}", event.prefix, event.text.trim()); + } else if event.log_level < 40 { + event!(target: "mpv", Level::WARN, "[{}] {}", event.prefix, event.text.trim()); + } else if event.log_level < 50 { + event!(target: "mpv", Level::INFO, "[{}] {}", event.prefix, event.text.trim()); + } else if event.log_level < 70 { + event!(target: "mpv", Level::DEBUG, "[{}] {}", event.prefix, event.text.trim()); + } else { + event!(target: "mpv", Level::TRACE, "[{}] {}", event.prefix, event.text.trim()); + }; + } + _ => event!(Level::DEBUG, "unhandled {event:?}"), } }