From 27eeab7b400eb35eb66e39ce4c6945b3d393121c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Mon, 10 Jan 2022 18:33:08 +0100 Subject: [PATCH] logger: add column for log level Add a column to separate the message from the log level. --- src/app.rs | 29 +++++++++++++++-------------- src/logger.rs | 8 ++++---- src/pipeline.rs | 37 +++++++++++++++++++++---------------- src/plugindialogs.rs | 5 +++-- 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/app.rs b/src/app.rs index 4c3c8a5..c66f376 100644 --- a/src/app.rs +++ b/src/app.rs @@ -329,7 +329,7 @@ impl GPSApp { } fn reset_logger_list(&self, logger_list: &TreeView) { - let model = ListStore::new(&[String::static_type()]); + let model = ListStore::new(&[String::static_type(), String::static_type()]); logger_list.set_model(Some(&model)); } @@ -340,11 +340,17 @@ impl GPSApp { .expect("Couldn't get window"); let column = TreeViewColumn::new(); let cell = CellRendererText::new(); - column.pack_start(&cell, true); // Association of the view's column with the model's `id` column. column.add_attribute(&cell, "text", 0); - column.set_title(""); + column.set_title("LEVEL"); + logger_list.append_column(&column); + let column = TreeViewColumn::new(); + let cell = CellRendererText::new(); + column.pack_start(&cell, true); + // Association of the view's column with the model's `id` column. + column.add_attribute(&cell, "text", 1); + column.set_title("LOG"); logger_list.append_column(&column); self.reset_logger_list(&logger_list); } @@ -358,7 +364,9 @@ impl GPSApp { let list_store = model .dynamic_cast::() .expect("Could not cast to ListStore"); - list_store.insert_with_values(None, &[(0, &log_entry)]); + if let Some(log) = log_entry.split_once('\t') { + list_store.insert_with_values(None, &[(0, &log.0), (1, &log.1)]); + } } } @@ -547,11 +555,8 @@ impl GPSApp { let pipeline = app.pipeline.borrow(); if pipeline.state() == PipelineState::Stopped { if let Err(err) = pipeline.create_pipeline(&pipeline.render_gst_launch(&graph_view)) { - GPSApp::show_error_dialog( - false, - format!("Unable to start a pipeline: {}", err) - .as_str(), - ); + GPS_ERROR!("Unable to start a pipeline: {}", err); + } pipeline.set_state(PipelineState::Playing).expect("Unable to change state"); } else if pipeline.state() == PipelineState::Paused { @@ -571,11 +576,7 @@ impl GPSApp { let pipeline = app.pipeline.borrow(); if pipeline.state() == PipelineState::Stopped { if let Err(err) = pipeline.create_pipeline(&pipeline.render_gst_launch(&graph_view)) { - GPSApp::show_error_dialog( - false, - format!("Unable to start a pipeline: {}", err) - .as_str(), - ); + GPS_ERROR!("Unable to start a pipeline: {}", err); } pipeline.set_state(PipelineState::Paused).expect("Unable to change state"); } else if pipeline.state() == PipelineState::Paused { diff --git a/src/logger.rs b/src/logger.rs index aaa421c..0f90ca3 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -15,9 +15,9 @@ struct Logger { #[derive(Debug, Eq, Ord, PartialEq, PartialOrd)] pub enum LogLevel { Error, - _Warning, + Warning, Info, - _Log, + Log, Debug, } impl fmt::Display for LogLevel { @@ -90,8 +90,8 @@ pub fn print_log(log_level: LogLevel, msg: String) { .lock() .expect("guarded"); - if let Err(e) = sender.get_mut().send(format!("{}:{}", log_level, msg)) { - println!("Error: {}", e) + if let Err(e) = sender.get_mut().send(format!("{}\t{}", log_level, msg)) { + println!("Error: {} for {}", e, msg); }; } } diff --git a/src/pipeline.rs b/src/pipeline.rs index 9d07743..d10e938 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -103,25 +103,24 @@ impl Pipeline { /* create playbin */ let pipeline = gst::parse_launch(&description.to_string())?; - let pipeline = pipeline - .downcast::() - .expect("Couldn't downcast pipeline"); + if let Ok(pipeline) = pipeline.downcast::() { + //pipeline.set_property_message_forward(true); - //pipeline.set_property_message_forward(true); + let bus = pipeline.bus().expect("Pipeline had no bus"); + let pipeline_weak = self.downgrade(); + bus.add_watch_local(move |_bus, msg| { + let pipeline = upgrade_weak!(pipeline_weak, glib::Continue(false)); - let bus = pipeline.bus().expect("Pipeline had no bus"); - let pipeline_weak = self.downgrade(); - bus.add_watch_local(move |_bus, msg| { - let pipeline = upgrade_weak!(pipeline_weak, glib::Continue(false)); + pipeline.on_pipeline_message(msg); - pipeline.on_pipeline_message(msg); - - glib::Continue(true) - })?; - - *self.pipeline.borrow_mut() = Some(pipeline); - /* start playing */ + glib::Continue(true) + })?; + *self.pipeline.borrow_mut() = Some(pipeline); + /* start playing */ + } else { + GPS_ERROR!("Couldn't downcast pipeline") + } Ok(()) } @@ -152,6 +151,12 @@ impl Pipeline { use gst::MessageView; match msg.view() { MessageView::Error(err) => { + GPS_ERROR!( + "Error from {:?}: {} ({:?})", + err.src().map(|s| s.path_string()), + err.error(), + err.debug() + ); GPSApp::show_error_dialog( false, format!( @@ -168,7 +173,7 @@ impl Pipeline { // the UI in case something goes wrong Some(s) if s.name() == "warning" => { let text = s.get::<&str>("text").expect("Warning message without text"); - GPSApp::show_error_dialog(false, text); + GPS_WARN!("{}", text); } _ => (), }, diff --git a/src/plugindialogs.rs b/src/plugindialogs.rs index 034b8d6..36b4f9e 100644 --- a/src/plugindialogs.rs +++ b/src/plugindialogs.rs @@ -17,6 +17,7 @@ // // SPDX-License-Identifier: GPL-3.0-only use crate::app::GPSApp; +use crate::logger; use crate::pipeline::ElementInfo; use crate::pipeline::Pipeline; use gtk::glib; @@ -153,7 +154,7 @@ pub fn display_plugin_properties(app: &GPSApp, element_name: &str, node_id: u32) entry.set_widget_name(&name); entry.connect_changed( glib::clone!(@weak entry, @strong update_properties => move |_| { - println!("{}:{}", entry.widget_name(), entry.text()); + GPS_LOG!("{}:{}", entry.widget_name(), entry.text()); update_properties.borrow_mut().insert(entry.widget_name().to_string(), entry.text().to_string()); }), ); @@ -176,6 +177,6 @@ pub fn display_plugin_properties(app: &GPSApp, element_name: &str, node_id: u32) dialog.show(); for p in update_properties.borrow().values() { - println!("updated properties {}", p); + GPS_LOG!("updated properties {}", p); } }