diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-03-13 17:22:30 +0100 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-03-13 17:22:30 +0100 |
| commit | ded18096adbafc3e56fb229e9e83fbb35fd521c8 (patch) | |
| tree | 8a89a2b7bd424f7cbad2c24343594292acd7e0c8 /src/bin | |
| parent | fix: admonition in README (diff) | |
| download | sl0pstatus-ded18096adbafc3e56fb229e9e83fbb35fd521c8.tar.gz sl0pstatus-ded18096adbafc3e56fb229e9e83fbb35fd521c8.tar.xz sl0pstatus-ded18096adbafc3e56fb229e9e83fbb35fd521c8.zip | |
feat(dev): add tracing feature
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/zjstatus.rs | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/bin/zjstatus.rs b/src/bin/zjstatus.rs index 07c38a0..1f0de0e 100644 --- a/src/bin/zjstatus.rs +++ b/src/bin/zjstatus.rs @@ -8,10 +8,13 @@ use widgets::{ tabs::TabsWidget, widget::Widget, }; + +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; + use zellij_tile::prelude::*; use chrono::Local; -use std::{collections::BTreeMap, sync::Arc, usize}; +use std::{collections::BTreeMap, fs::File, sync::Arc, usize}; use uuid::Uuid; use zjstatus::{ @@ -31,8 +34,25 @@ struct State { #[cfg(not(test))] register_plugin!(State); +#[cfg(feature = "tracing")] +fn init_tracing() { + let file = File::create(".zjstatus.log"); + let file = match file { + Ok(file) => file, + Err(error) => panic!("Error: {:?}", error), + }; + let debug_log = tracing_subscriber::fmt::layer().with_writer(Arc::new(file)); + + tracing_subscriber::registry().with(debug_log).init(); + + tracing::info!("tracing initialized"); +} + impl ZellijPlugin for State { fn load(&mut self, configuration: BTreeMap<String, String>) { + #[cfg(feature = "tracing")] + init_tracing(); + // we need the ReadApplicationState permission to receive the ModeUpdate and TabUpdate // events // we need the RunCommands permission to run "cargo test" in a floating window @@ -41,6 +61,7 @@ impl ZellijPlugin for State { PermissionType::ChangeApplicationState, PermissionType::RunCommands, ]); + subscribe(&[ EventType::Mouse, EventType::ModeUpdate, @@ -70,11 +91,16 @@ impl ZellijPlugin for State { }; } + #[tracing::instrument(skip_all, fields(event_type))] fn update(&mut self, event: Event) -> bool { let mut should_render = false; match event { Event::Mouse(mouse_info) => { + tracing::Span::current().record("event_type", "Event::Mouse"); + tracing::debug!(mouse = ?mouse_info); + if !self.got_permissions { + tracing::info!("no permissions"); return false; } @@ -85,7 +111,11 @@ impl ZellijPlugin for State { ); } Event::ModeUpdate(mode_info) => { + tracing::Span::current().record("event_type", "Event::ModeUpdate"); + tracing::debug!(mode = ?mode_info.mode); + if !self.got_permissions { + tracing::info!("no permissions"); return false; } @@ -94,7 +124,11 @@ impl ZellijPlugin for State { should_render = true; } Event::PaneUpdate(pane_info) => { + tracing::Span::current().record("event_type", "Event::PaneUpdate"); + tracing::debug!(pane_count = ?pane_info.panes.len()); + if !self.got_permissions { + tracing::info!("no permissions"); return false; } @@ -111,12 +145,23 @@ impl ZellijPlugin for State { should_render = true; } - Event::PermissionRequestResult(_result) => { + Event::PermissionRequestResult(result) => { + tracing::Span::current().record("event_type", "Event::PermissionRequestResult"); + tracing::debug!(result = ?result); set_selectable(false); self.got_permissions = true; } Event::RunCommandResult(exit_code, stdout, stderr, context) => { + tracing::Span::current().record("event_type", "Event::RunCommandResult"); + tracing::debug!( + exit_code = ?exit_code, + stdout = ?String::from_utf8(stdout.clone()), + stderr = ?String::from_utf8(stderr.clone()), + context = ?context + ); + if !self.got_permissions { + tracing::info!("no permissions"); return false; } self.state.cache_mask = UpdateEventMask::Command as u8; @@ -144,7 +189,10 @@ impl ZellijPlugin for State { } } Event::SessionUpdate(session_info, _) => { + tracing::Span::current().record("event_type", "Event::SessionUpdate"); + if !self.got_permissions { + tracing::info!("no permissions"); return false; } @@ -166,7 +214,11 @@ impl ZellijPlugin for State { should_render = true; } Event::TabUpdate(tab_info) => { + tracing::Span::current().record("event_type", "Event::TabUpdate"); + tracing::debug!(tab_count = ?tab_info.len()); + if !self.got_permissions { + tracing::info!("no permissions"); return false; } @@ -216,5 +268,7 @@ fn register_widgets(configuration: &BTreeMap<String, String>) -> BTreeMap<String ); widget_map.insert("tabs".to_owned(), Arc::new(TabsWidget::new(configuration))); + tracing::debug!("registered widgets: {:?}", widget_map.keys()); + widget_map } |
