mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-26 03:21:03 +00:00
gstreamer: Add DebugCategory::above_threshold()
to check if the category's threshold is above the given level
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
This commit is contained in:
parent
b58d518aa3
commit
355ebc243f
1 changed files with 26 additions and 50 deletions
|
@ -129,6 +129,14 @@ impl DebugCategory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn above_threshold(self, level: crate::DebugLevel) -> bool {
|
||||||
|
match self.0 {
|
||||||
|
Some(cat) => unsafe { cat.as_ref().threshold >= level.into_glib() },
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[doc(alias = "get_color")]
|
#[doc(alias = "get_color")]
|
||||||
#[doc(alias = "gst_debug_category_get_color")]
|
#[doc(alias = "gst_debug_category_get_color")]
|
||||||
pub fn color(self) -> crate::DebugColorFlags {
|
pub fn color(self) -> crate::DebugColorFlags {
|
||||||
|
@ -175,16 +183,9 @@ impl DebugCategory {
|
||||||
line: u32,
|
line: u32,
|
||||||
args: fmt::Arguments,
|
args: fmt::Arguments,
|
||||||
) {
|
) {
|
||||||
let cat = match self.0 {
|
if !self.above_threshold(level) {
|
||||||
Some(cat) => cat,
|
|
||||||
None => return,
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
if level.into_glib() as i32 > cat.as_ref().threshold {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.log_unfiltered(obj, level, file, function, line, args)
|
self.log_unfiltered(obj, level, file, function, line, args)
|
||||||
}
|
}
|
||||||
|
@ -200,16 +201,9 @@ impl DebugCategory {
|
||||||
line: u32,
|
line: u32,
|
||||||
msg: &glib::GStr,
|
msg: &glib::GStr,
|
||||||
) {
|
) {
|
||||||
let cat = match self.0 {
|
if !self.above_threshold(level) {
|
||||||
Some(cat) => cat,
|
|
||||||
None => return,
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
if level.into_glib() as i32 > cat.as_ref().threshold {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.log_literal_unfiltered(obj, level, file, function, line, msg)
|
self.log_literal_unfiltered(obj, level, file, function, line, msg)
|
||||||
}
|
}
|
||||||
|
@ -300,16 +294,9 @@ impl DebugCategory {
|
||||||
line: u32,
|
line: u32,
|
||||||
args: fmt::Arguments,
|
args: fmt::Arguments,
|
||||||
) {
|
) {
|
||||||
let cat = match self.0 {
|
if !self.above_threshold(level) {
|
||||||
Some(cat) => cat,
|
|
||||||
None => return,
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
if level.into_glib() as i32 > cat.as_ref().threshold {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let mut w = glib::GStringBuilder::default();
|
let mut w = glib::GStringBuilder::default();
|
||||||
|
|
||||||
|
@ -334,16 +321,9 @@ impl DebugCategory {
|
||||||
line: u32,
|
line: u32,
|
||||||
msg: &glib::GStr,
|
msg: &glib::GStr,
|
||||||
) {
|
) {
|
||||||
let cat = match self.0 {
|
if !self.above_threshold(level) {
|
||||||
Some(cat) => cat,
|
|
||||||
None => return,
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
if level.into_glib() as i32 > cat.as_ref().threshold {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.log_id_literal_unfiltered(id, level, file, function, line, msg);
|
self.log_id_literal_unfiltered(id, level, file, function, line, msg);
|
||||||
}
|
}
|
||||||
|
@ -654,10 +634,9 @@ macro_rules! log_with_level(
|
||||||
// Check the log level before using `format_args!` otherwise
|
// Check the log level before using `format_args!` otherwise
|
||||||
// formatted arguments are evaluated even if we end up not logging.
|
// formatted arguments are evaluated even if we end up not logging.
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
if $level <= $cat.threshold() {
|
if $cat.above_threshold($level) {
|
||||||
use $crate::glib::Cast;
|
use $crate::glib::Cast;
|
||||||
|
|
||||||
#[allow(unused_unsafe)]
|
|
||||||
let obj = unsafe { $obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
let obj = unsafe { $obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
||||||
$crate::DebugCategory::log_literal_unfiltered(
|
$crate::DebugCategory::log_literal_unfiltered(
|
||||||
$cat.clone(),
|
$cat.clone(),
|
||||||
|
@ -674,10 +653,9 @@ macro_rules! log_with_level(
|
||||||
// Check the log level before using `format_args!` otherwise
|
// Check the log level before using `format_args!` otherwise
|
||||||
// formatted arguments are evaluated even if we end up not logging.
|
// formatted arguments are evaluated even if we end up not logging.
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
if $level <= $cat.threshold() {
|
if $cat.above_threshold($level) {
|
||||||
use $crate::glib::Cast;
|
use $crate::glib::Cast;
|
||||||
|
|
||||||
#[allow(unused_unsafe)]
|
|
||||||
let obj = unsafe { $obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
let obj = unsafe { $obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
||||||
$crate::DebugCategory::log_unfiltered(
|
$crate::DebugCategory::log_unfiltered(
|
||||||
$cat.clone(),
|
$cat.clone(),
|
||||||
|
@ -694,11 +672,10 @@ macro_rules! log_with_level(
|
||||||
// Check the log level before using `format_args!` otherwise
|
// Check the log level before using `format_args!` otherwise
|
||||||
// formatted arguments are evaluated even if we end up not logging.
|
// formatted arguments are evaluated even if we end up not logging.
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
if $level <= $cat.threshold() {
|
if $cat.above_threshold($level) {
|
||||||
use $crate::glib::Cast;
|
use $crate::glib::Cast;
|
||||||
|
|
||||||
let obj = $imp.obj();
|
let obj = $imp.obj();
|
||||||
#[allow(unused_unsafe)]
|
|
||||||
let obj = unsafe { obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
let obj = unsafe { obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
||||||
$crate::DebugCategory::log_literal_unfiltered(
|
$crate::DebugCategory::log_literal_unfiltered(
|
||||||
$cat.clone(),
|
$cat.clone(),
|
||||||
|
@ -715,11 +692,10 @@ macro_rules! log_with_level(
|
||||||
// Check the log level before using `format_args!` otherwise
|
// Check the log level before using `format_args!` otherwise
|
||||||
// formatted arguments are evaluated even if we end up not logging.
|
// formatted arguments are evaluated even if we end up not logging.
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
if $level <= $cat.threshold() {
|
if $cat.above_threshold($level) {
|
||||||
use $crate::glib::Cast;
|
use $crate::glib::Cast;
|
||||||
|
|
||||||
let obj = $imp.obj();
|
let obj = $imp.obj();
|
||||||
#[allow(unused_unsafe)]
|
|
||||||
let obj = unsafe { obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
let obj = unsafe { obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
||||||
$crate::DebugCategory::log_unfiltered(
|
$crate::DebugCategory::log_unfiltered(
|
||||||
$cat.clone(),
|
$cat.clone(),
|
||||||
|
@ -736,7 +712,7 @@ macro_rules! log_with_level(
|
||||||
// Check the log level before using `format_args!` otherwise
|
// Check the log level before using `format_args!` otherwise
|
||||||
// formatted arguments are evaluated even if we end up not logging.
|
// formatted arguments are evaluated even if we end up not logging.
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
if $level <= $cat.threshold() {
|
if $cat.above_threshold($level) {
|
||||||
$crate::DebugCategory::log_id_literal_unfiltered(
|
$crate::DebugCategory::log_id_literal_unfiltered(
|
||||||
$cat.clone(),
|
$cat.clone(),
|
||||||
Some($crate::glib::gstr!($id)),
|
Some($crate::glib::gstr!($id)),
|
||||||
|
@ -752,7 +728,7 @@ macro_rules! log_with_level(
|
||||||
// Check the log level before using `format_args!` otherwise
|
// Check the log level before using `format_args!` otherwise
|
||||||
// formatted arguments are evaluated even if we end up not logging.
|
// formatted arguments are evaluated even if we end up not logging.
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
if $level <= $cat.threshold() {
|
if $cat.above_threshold($level) {
|
||||||
$crate::DebugCategory::log_id_unfiltered(
|
$crate::DebugCategory::log_id_unfiltered(
|
||||||
$cat.clone(),
|
$cat.clone(),
|
||||||
Some($crate::glib::gstr!($id)),
|
Some($crate::glib::gstr!($id)),
|
||||||
|
@ -768,7 +744,7 @@ macro_rules! log_with_level(
|
||||||
// Check the log level before using `format_args!` otherwise
|
// Check the log level before using `format_args!` otherwise
|
||||||
// formatted arguments are evaluated even if we end up not logging.
|
// formatted arguments are evaluated even if we end up not logging.
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
if $level <= $cat.threshold() {
|
if $cat.above_threshold($level) {
|
||||||
$crate::DebugCategory::log_id_literal_unfiltered(
|
$crate::DebugCategory::log_id_literal_unfiltered(
|
||||||
$cat.clone(),
|
$cat.clone(),
|
||||||
Some($id),
|
Some($id),
|
||||||
|
@ -784,7 +760,7 @@ macro_rules! log_with_level(
|
||||||
// Check the log level before using `format_args!` otherwise
|
// Check the log level before using `format_args!` otherwise
|
||||||
// formatted arguments are evaluated even if we end up not logging.
|
// formatted arguments are evaluated even if we end up not logging.
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
if $level <= $cat.threshold() {
|
if $cat.above_threshold($level) {
|
||||||
$crate::DebugCategory::log_id_unfiltered(
|
$crate::DebugCategory::log_id_unfiltered(
|
||||||
$cat.clone(),
|
$cat.clone(),
|
||||||
Some($id),
|
Some($id),
|
||||||
|
@ -800,7 +776,7 @@ macro_rules! log_with_level(
|
||||||
// Check the log level before using `format_args!` otherwise
|
// Check the log level before using `format_args!` otherwise
|
||||||
// formatted arguments are evaluated even if we end up not logging.
|
// formatted arguments are evaluated even if we end up not logging.
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
if $level <= $cat.threshold() {
|
if $cat.above_threshold($level) {
|
||||||
$crate::DebugCategory::log_literal_unfiltered(
|
$crate::DebugCategory::log_literal_unfiltered(
|
||||||
$cat.clone(),
|
$cat.clone(),
|
||||||
None as Option<&$crate::glib::Object>,
|
None as Option<&$crate::glib::Object>,
|
||||||
|
@ -816,7 +792,7 @@ macro_rules! log_with_level(
|
||||||
// Check the log level before using `format_args!` otherwise
|
// Check the log level before using `format_args!` otherwise
|
||||||
// formatted arguments are evaluated even if we end up not logging.
|
// formatted arguments are evaluated even if we end up not logging.
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
if $level <= $cat.threshold() {
|
if $cat.above_threshold($level) {
|
||||||
$crate::DebugCategory::log_unfiltered(
|
$crate::DebugCategory::log_unfiltered(
|
||||||
$cat.clone(),
|
$cat.clone(),
|
||||||
None as Option<&$crate::glib::Object>,
|
None as Option<&$crate::glib::Object>,
|
||||||
|
|
Loading…
Reference in a new issue