Only format strings, etc in debug log handler if the configured threshold is higher than the level

This commit is contained in:
Sebastian Dröge 2016-12-26 10:53:36 +01:00
parent fb21d62868
commit c9aad84898

View file

@ -101,15 +101,11 @@ impl Drain for GstDebugDrain {
line: u32, line: u32,
object: *const c_void, object: *const c_void,
message: *const c_char); 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() { let level = match record.level() {
Level::Critical | Level::Error => 1, Level::Critical | Level::Error => 1,
Level::Warning => 2, Level::Warning => 2,
@ -118,11 +114,19 @@ impl Drain for GstDebugDrain {
Level::Trace => 7, Level::Trace => 7,
}; };
extern "C" { let threshold = unsafe { gst_debug_category_get_threshold(self.category) };
fn g_weak_ref_get(weak_ref: &*const c_void) -> *const c_void;
fn gst_object_unref(obj: *const c_void); 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 { unsafe {
let element = if self.element.is_null() { let element = if self.element.is_null() {
ptr::null() ptr::null()