From c9aad84898692906509e2f853869325f6776bf08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 26 Dec 2016 10:53:36 +0100 Subject: [PATCH] Only format strings, etc in debug log handler if the configured threshold is higher than the level --- gst-plugin/src/log.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/gst-plugin/src/log.rs b/gst-plugin/src/log.rs index 67208750..506684ee 100644 --- a/gst-plugin/src/log.rs +++ b/gst-plugin/src/log.rs @@ -101,15 +101,11 @@ impl Drain for GstDebugDrain { line: u32, object: *const c_void, message: *const c_char); + fn gst_debug_category_get_threshold(category: *const c_void) -> u32; + fn g_weak_ref_get(weak_ref: &*const c_void) -> *const c_void; + fn gst_object_unref(obj: *const c_void); } - let file_cstr = CString::new(record.file().as_bytes()).unwrap(); - - // TODO: Probably want to include module? - let function_cstr = CString::new(record.function().as_bytes()).unwrap(); - - let message_cstr = CString::new(fmt::format(record.msg()).as_bytes()).unwrap(); - let level = match record.level() { Level::Critical | Level::Error => 1, Level::Warning => 2, @@ -118,11 +114,19 @@ impl Drain for GstDebugDrain { Level::Trace => 7, }; - extern "C" { - fn g_weak_ref_get(weak_ref: &*const c_void) -> *const c_void; - fn gst_object_unref(obj: *const c_void); + let threshold = unsafe { gst_debug_category_get_threshold(self.category) }; + + if level > threshold { + return Ok(()); } + let file_cstr = CString::new(record.file().as_bytes()).unwrap(); + + // TODO: Probably want to include module? + let function_cstr = CString::new(record.function().as_bytes()).unwrap(); + + let message_cstr = CString::new(fmt::format(record.msg()).as_bytes()).unwrap(); + unsafe { let element = if self.element.is_null() { ptr::null()