From b754cb1e112e0c8d0da2cc676442a8e679a32223 Mon Sep 17 00:00:00 2001 From: psykose Date: Mon, 4 Nov 2024 10:12:13 +0100 Subject: [PATCH] debug logging idk --- Cargo.lock | 69 ++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/application.rs | 3 +- src/main.rs | 10 +++++++ src/mpris.rs | 3 +- src/mpris/player.rs | 3 +- src/mpv/handle.rs | 9 +++--- src/playbin.rs | 21 +++++++++----- src/subsonic.rs | 3 +- src/ui/play_queue.rs | 3 +- src/ui/playbar.rs | 3 +- src/ui/setup.rs | 3 +- src/ui/window.rs | 3 +- 13 files changed, 116 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6cf48e1..42bd704 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -232,6 +232,8 @@ dependencies = [ "reqwest", "serde", "tokio", + "tracing", + "tracing-subscriber", "url", "zbus 5.0.1", ] @@ -1450,6 +1452,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num" version = "0.4.3" @@ -1628,6 +1640,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "pango" version = "0.20.4" @@ -2109,6 +2127,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "1.3.0" @@ -2245,6 +2272,16 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -2368,6 +2405,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", ] [[package]] @@ -2431,6 +2494,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "version-compare" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 22bf015..2ce638b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,8 @@ reqwest = { version = "0.12.9", default-features = false, features = [ ] } serde = { version = "1.0.214", features = ["derive"] } tokio = { version = "1", features = ["rt-multi-thread"] } +tracing = { version = "0.1.40", default-features = false, features = ["attributes", "std"] } +tracing-subscriber = "0.3.18" url = "2.5.2" zbus = { version = "5.0.1", features = ["chrono"] } diff --git a/src/application.rs b/src/application.rs index 28961df..4ad0547 100644 --- a/src/application.rs +++ b/src/application.rs @@ -2,6 +2,7 @@ mod imp { use crate::ui; use adw::{prelude::*, subclass::prelude::*}; use gtk::glib; + use tracing::{event, Level}; #[derive(Default)] pub struct Application {} @@ -36,7 +37,7 @@ mod imp { impl Drop for Application { fn drop(&mut self) { - println!("dropping AudreyApplication"); + event!(Level::DEBUG, "dropping AudreyApplication"); } } } diff --git a/src/main.rs b/src/main.rs index a0422fa..3a61aa3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,9 +28,19 @@ use gtk::{gio, glib}; pub mod mpv; +#[cfg(debug_assertions)] +fn init_tracing() { + tracing_subscriber::fmt::init(); +} + +#[cfg(not(debug_assertions))] +fn init_tracing() {} + fn main() -> glib::ExitCode { gio::resources_register_include!("audrey.gresource").expect("could not register resources"); + init_tracing(); + ui::Playbar::ensure_type(); ui::PlayQueue::ensure_type(); diff --git a/src/mpris.rs b/src/mpris.rs index 6266b25..3457edf 100644 --- a/src/mpris.rs +++ b/src/mpris.rs @@ -3,6 +3,7 @@ pub use player::Player; use adw::prelude::*; use gtk::glib; +use tracing::{event, Level}; pub struct Mpris { window: glib::SendWeakRef, @@ -96,6 +97,6 @@ impl Mpris { impl Drop for Mpris { fn drop(&mut self) { - println!("dropping Mpris"); + event!(Level::DEBUG, "dropping Mpris"); } } diff --git a/src/mpris/player.rs b/src/mpris/player.rs index 987e76d..e0769eb 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -2,6 +2,7 @@ use crate::{Playbin, PlaybinSong}; use gtk::glib::spawn_future_local; use std::collections::HashMap; use std::rc::{Rc, Weak}; +use tracing::{event, Level}; use zbus::zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Value}; const MICROSECONDS: f64 = 1e6; // in a second @@ -576,6 +577,6 @@ impl LocalPlayer { impl Drop for Player { fn drop(&mut self) { - println!("dropping MprisPlayer"); + event!(Level::DEBUG, "dropping MprisPlayer"); } } diff --git a/src/mpv/handle.rs b/src/mpv/handle.rs index 4407443..d8ed31d 100644 --- a/src/mpv/handle.rs +++ b/src/mpv/handle.rs @@ -1,13 +1,14 @@ -use super::{event, ffi, Error, Event as MpvEvent, GetProperty, SetProperty}; -use event::{ +use super::event::{ EndFileEvent, EndFileReason, HookEvent, LogMessageEvent, PropertyEvent, StartFileEvent, }; +use super::{ffi, Error, Event as MpvEvent, GetProperty, SetProperty}; use event_listener::{Event, EventListener, IntoNotification}; use std::cell::{RefCell, RefMut}; use std::ffi::{c_char, c_void, CStr, CString}; use std::fmt; use std::pin::Pin; use std::ptr::NonNull; +use tracing::{event, Level}; pub struct Handle { inner: NonNull, @@ -254,7 +255,7 @@ impl Handle { impl Drop for Handle { fn drop(&mut self) { - println!("dropping MpvHandle"); + event!(Level::DEBUG, "dropping MpvHandle"); // let any executor ticking tasks know we're ded self.wakeup.notify(u32::MAX.relaxed()); @@ -265,7 +266,7 @@ impl Drop for Handle { } // drain event queue (we're &mut so we know we have exclusive access) while let Some(event) = self.wait_event(0.0) { - println!("drained event on drop: {event:?}"); + event!(Level::DEBUG, "drained event on drop: {:?}", event); } unsafe { diff --git a/src/playbin.rs b/src/playbin.rs index c9588c7..1499d2b 100644 --- a/src/playbin.rs +++ b/src/playbin.rs @@ -2,6 +2,7 @@ use crate::mpv; use crate::signal::{Signal, SignalEmitter}; use event_listener::EventListener; use std::cell::{Ref, RefCell}; +use tracing::{event, span, Level}; use url::Url; pub trait PlaybinEntry { @@ -185,30 +186,36 @@ where } fn handle_event(&self, event: mpv::Event) { + let span = span!(Level::DEBUG, "mpv_handle_event"); + let _guart = span.enter(); match event { mpv::Event::PropertyChange(event) => match event.reply_userdata { 0 => { assert_eq!(&event.name, "volume"); self.volume_changed.emit(self, ()); - dbg!(self.volume()); + event!(Level::DEBUG, "volume change {}", self.volume()); } 1 => { assert_eq!(&event.name, "mute"); self.muted_changed.emit(self, ()); - dbg!(self.muted()); + event!(Level::DEBUG, "mute state change to {}", self.muted()); } 2 => { assert_eq!(&event.name, "pause"); self.paused_changed.emit(self, ()); - dbg!(self.paused()); + event!(Level::DEBUG, "pause state change to {}", self.paused()); } 3 => { assert_eq!(&event.name, "playlist-pos"); self.current_entry_changed.emit(self, ()); - dbg!(self.current_entry()); + event!( + Level::DEBUG, + "playlist-pos change {:?}", + self.current_entry() + ); } _ => unreachable!(), @@ -217,8 +224,8 @@ where mpv::Event::Hook(event) => match event.reply_userdata { 0 => { assert_eq!(&event.name, "on_before_start_file"); + event!(Level::DEBUG, "on_before_start_file triggered"); // just use this as a barrier - println!("on_before_start_file triggered"); self.mpv.continue_hook(event.id).unwrap(); } @@ -237,7 +244,7 @@ where ); } - _ => println!("mpv event {:?}", event), + _ => event!(Level::DEBUG, "mpv event {:?}", event), } } @@ -272,7 +279,7 @@ where impl Drop for Playbin { fn drop(&mut self) { - println!("dropping Playbin2"); + event!(Level::DEBUG, "dropping Playbin2"); self.mpv.command(["quit"]).unwrap(); } } diff --git a/src/subsonic.rs b/src/subsonic.rs index 7c48a1e..3f3b9bc 100644 --- a/src/subsonic.rs +++ b/src/subsonic.rs @@ -2,6 +2,7 @@ pub mod schema; use md5::Digest; use rand::Rng; +use tracing::{event, Level}; fn runtime() -> &'static tokio::runtime::Runtime { static RUNTIME: std::sync::OnceLock = std::sync::OnceLock::new(); @@ -187,6 +188,6 @@ impl Client { impl Drop for Client { fn drop(&mut self) { - println!("dropping SubsonicClient"); + event!(Level::DEBUG, "dropping SubsonicClient"); } } diff --git a/src/ui/play_queue.rs b/src/ui/play_queue.rs index 5ba6846..e6510e4 100644 --- a/src/ui/play_queue.rs +++ b/src/ui/play_queue.rs @@ -7,6 +7,7 @@ mod imp { use glib::subclass::InitializingObject; use std::cell::RefCell; use std::rc::Rc; + use tracing::{event, Level}; #[derive(gtk::CompositeTemplate, glib::Properties, Default)] #[template(resource = "/eu/callcc/audrey/play_queue.ui")] @@ -99,7 +100,7 @@ mod imp { impl Drop for PlayQueue { fn drop(&mut self) { - println!("dropping AudreyUiPlayQueue"); + event!(Level::DEBUG, "dropping AudreyUiPlayQueue"); } } } diff --git a/src/ui/playbar.rs b/src/ui/playbar.rs index abaf795..4cd2f77 100644 --- a/src/ui/playbar.rs +++ b/src/ui/playbar.rs @@ -5,6 +5,7 @@ mod imp { use glib::subclass::InitializingObject; use gtk::{gdk, glib}; use std::cell::{Cell, RefCell}; + use tracing::{event, Level}; #[derive(glib::Properties, gtk::CompositeTemplate, Default)] #[properties(wrapper_type = super::Playbar)] @@ -160,7 +161,7 @@ mod imp { impl Drop for Playbar { fn drop(&mut self) { - println!("dropping AudreyUiPlaybar"); + event!(Level::DEBUG, "dropping AudreyUiPlaybar"); } } } diff --git a/src/ui/setup.rs b/src/ui/setup.rs index e503f6c..190c208 100644 --- a/src/ui/setup.rs +++ b/src/ui/setup.rs @@ -4,6 +4,7 @@ mod imp { use glib::subclass::InitializingObject; use std::cell::{Cell, RefCell}; use std::rc::Rc; + use tracing::{event, Level}; #[derive(gtk::CompositeTemplate, glib::Properties, Default)] #[template(resource = "/eu/callcc/audrey/setup.ui")] @@ -117,7 +118,7 @@ mod imp { impl Drop for Setup { fn drop(&mut self) { - println!("dropping AudreyUiSetup"); + event!(Level::DEBUG, "dropping AudreyUiSetup"); } } } diff --git a/src/ui/window.rs b/src/ui/window.rs index 437e65f..dbe0d72 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -6,6 +6,7 @@ mod imp { use gtk::{gdk, glib}; use std::cell::{Cell, RefCell}; use std::rc::Rc; + use tracing::{event, Level}; #[derive(gtk::CompositeTemplate, glib::Properties, Default)] #[template(resource = "/eu/callcc/audrey/window.ui")] @@ -171,7 +172,7 @@ mod imp { impl Drop for Window { fn drop(&mut self) { - println!("dropping AudreyUiWindow"); + event!(Level::DEBUG, "dropping AudreyUiWindow"); } } }