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 13560b1b5f
commit 9bd2f9d5a4
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) {
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::<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();
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 {

View file

@ -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);
};
}
}

View file

@ -103,10 +103,7 @@ impl Pipeline {
/* create playbin */
let pipeline = gst::parse_launch(&description.to_string())?;
let pipeline = pipeline
.downcast::<gst::Pipeline>()
.expect("Couldn't downcast pipeline");
if let Ok(pipeline) = pipeline.downcast::<gst::Pipeline>() {
//pipeline.set_property_message_forward(true);
let bus = pipeline.bus().expect("Pipeline had no bus");
@ -121,7 +118,9 @@ impl Pipeline {
*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);
}
_ => (),
},

View file

@ -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);
}
}