logger: add column for log level

Add a column to separate the message
from the log level.
This commit is contained in:
Stéphane Cerveau 2022-01-10 18:33:08 +01:00
parent a6a5d796ca
commit 27eeab7b40
4 changed files with 43 additions and 36 deletions

View file

@ -329,7 +329,7 @@ impl GPSApp {
} }
fn reset_logger_list(&self, logger_list: &TreeView) { 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)); logger_list.set_model(Some(&model));
} }
@ -340,11 +340,17 @@ impl GPSApp {
.expect("Couldn't get window"); .expect("Couldn't get window");
let column = TreeViewColumn::new(); let column = TreeViewColumn::new();
let cell = CellRendererText::new(); let cell = CellRendererText::new();
column.pack_start(&cell, true); column.pack_start(&cell, true);
// Association of the view's column with the model's `id` column. // Association of the view's column with the model's `id` column.
column.add_attribute(&cell, "text", 0); 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); logger_list.append_column(&column);
self.reset_logger_list(&logger_list); self.reset_logger_list(&logger_list);
} }
@ -358,7 +364,9 @@ impl GPSApp {
let list_store = model let list_store = model
.dynamic_cast::<ListStore>() .dynamic_cast::<ListStore>()
.expect("Could not cast to ListStore"); .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(); let pipeline = app.pipeline.borrow();
if pipeline.state() == PipelineState::Stopped { if pipeline.state() == PipelineState::Stopped {
if let Err(err) = pipeline.create_pipeline(&pipeline.render_gst_launch(&graph_view)) { if let Err(err) = pipeline.create_pipeline(&pipeline.render_gst_launch(&graph_view)) {
GPSApp::show_error_dialog( GPS_ERROR!("Unable to start a pipeline: {}", err);
false,
format!("Unable to start a pipeline: {}", err)
.as_str(),
);
} }
pipeline.set_state(PipelineState::Playing).expect("Unable to change state"); pipeline.set_state(PipelineState::Playing).expect("Unable to change state");
} else if pipeline.state() == PipelineState::Paused { } else if pipeline.state() == PipelineState::Paused {
@ -571,11 +576,7 @@ impl GPSApp {
let pipeline = app.pipeline.borrow(); let pipeline = app.pipeline.borrow();
if pipeline.state() == PipelineState::Stopped { if pipeline.state() == PipelineState::Stopped {
if let Err(err) = pipeline.create_pipeline(&pipeline.render_gst_launch(&graph_view)) { if let Err(err) = pipeline.create_pipeline(&pipeline.render_gst_launch(&graph_view)) {
GPSApp::show_error_dialog( GPS_ERROR!("Unable to start a pipeline: {}", err);
false,
format!("Unable to start a pipeline: {}", err)
.as_str(),
);
} }
pipeline.set_state(PipelineState::Paused).expect("Unable to change state"); pipeline.set_state(PipelineState::Paused).expect("Unable to change state");
} else if pipeline.state() == PipelineState::Paused { } else if pipeline.state() == PipelineState::Paused {

View file

@ -15,9 +15,9 @@ struct Logger {
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)] #[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum LogLevel { pub enum LogLevel {
Error, Error,
_Warning, Warning,
Info, Info,
_Log, Log,
Debug, Debug,
} }
impl fmt::Display for LogLevel { impl fmt::Display for LogLevel {
@ -90,8 +90,8 @@ pub fn print_log(log_level: LogLevel, msg: String) {
.lock() .lock()
.expect("guarded"); .expect("guarded");
if let Err(e) = sender.get_mut().send(format!("{}:{}", log_level, msg)) { if let Err(e) = sender.get_mut().send(format!("{}\t{}", log_level, msg)) {
println!("Error: {}", e) println!("Error: {} for {}", e, msg);
}; };
} }
} }

View file

@ -103,25 +103,24 @@ impl Pipeline {
/* create playbin */ /* create playbin */
let pipeline = gst::parse_launch(&description.to_string())?; let pipeline = gst::parse_launch(&description.to_string())?;
let pipeline = pipeline if let Ok(pipeline) = pipeline.downcast::<gst::Pipeline>() {
.downcast::<gst::Pipeline>() //pipeline.set_property_message_forward(true);
.expect("Couldn't downcast pipeline");
//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"); pipeline.on_pipeline_message(msg);
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); glib::Continue(true)
})?;
glib::Continue(true)
})?;
*self.pipeline.borrow_mut() = Some(pipeline);
/* start playing */
*self.pipeline.borrow_mut() = Some(pipeline);
/* start playing */
} else {
GPS_ERROR!("Couldn't downcast pipeline")
}
Ok(()) Ok(())
} }
@ -152,6 +151,12 @@ impl Pipeline {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {
MessageView::Error(err) => { MessageView::Error(err) => {
GPS_ERROR!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
GPSApp::show_error_dialog( GPSApp::show_error_dialog(
false, false,
format!( format!(
@ -168,7 +173,7 @@ impl Pipeline {
// the UI in case something goes wrong // the UI in case something goes wrong
Some(s) if s.name() == "warning" => { Some(s) if s.name() == "warning" => {
let text = s.get::<&str>("text").expect("Warning message without text"); let text = s.get::<&str>("text").expect("Warning message without text");
GPSApp::show_error_dialog(false, text); GPS_WARN!("{}", text);
} }
_ => (), _ => (),
}, },

View file

@ -17,6 +17,7 @@
// //
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
use crate::app::GPSApp; use crate::app::GPSApp;
use crate::logger;
use crate::pipeline::ElementInfo; use crate::pipeline::ElementInfo;
use crate::pipeline::Pipeline; use crate::pipeline::Pipeline;
use gtk::glib; 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.set_widget_name(&name);
entry.connect_changed( entry.connect_changed(
glib::clone!(@weak entry, @strong update_properties => move |_| { 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()); 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(); dialog.show();
for p in update_properties.borrow().values() { for p in update_properties.borrow().values() {
println!("updated properties {}", p); GPS_LOG!("updated properties {}", p);
} }
} }