gstreamer: Use obj = x instead of obj: x in debug log macros

And deprecate the old usage. This gives better tooling support, and
especially allows rustfmt to format the macro body correctly.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/513

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1477>
This commit is contained in:
Sebastian Dröge 2024-07-05 13:10:33 +03:00
parent 426d95bc6a
commit a871f71515
14 changed files with 491 additions and 179 deletions

View file

@ -459,7 +459,7 @@ mod video_filter {
frame: &mut VideoFrameRef<&mut gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.transform_fd_mem_ip(frame).map_err(|err| {
gst::error!(CAT, imp: self, "Failed to transform frame`: {}", err);
gst::error!(CAT, imp = self, "Failed to transform frame`: {}", err);
gst::FlowError::Error
})?;

View file

@ -80,7 +80,7 @@ mod mirror {
gst::debug!(
CAT,
imp: self,
imp = self,
"Compiling fragment shader {}",
FRAGMENT_SHADER
);
@ -99,7 +99,7 @@ mod mirror {
gst::debug!(
CAT,
imp: self,
imp = self,
"Successfully compiled and linked {:?}",
shader
);

View file

@ -142,7 +142,7 @@ mod fir_filter {
// Drop state
self.history.lock().unwrap().clear();
gst::info!(CAT, imp: self, "Stopped");
gst::info!(CAT, imp = self, "Stopped");
Ok(())
}
@ -155,7 +155,7 @@ mod fir_filter {
// Get coefficients and return directly if we have none
let coeffs = self.coeffs.lock().unwrap();
if coeffs.is_empty() {
gst::trace!(CAT, imp: self, "No coefficients set -- passthrough");
gst::trace!(CAT, imp = self, "No coefficients set -- passthrough");
return Ok(gst::FlowSuccess::Ok);
}
@ -183,7 +183,7 @@ mod fir_filter {
gst::trace!(
CAT,
imp: self,
imp = self,
"Transforming {} samples with filter of length {}",
samples.len(),
coeffs.len()

View file

@ -116,7 +116,7 @@ impl BaseTransformImpl for IirFilter {
}
let mut map = buf.map_writable().map_err(|_| {
gst::error!(CAT, imp: self, "Failed to map buffer writable");
gst::error!(CAT, imp = self, "Failed to map buffer writable");
gst::FlowError::Error
})?;
@ -166,7 +166,7 @@ impl AudioFilterImpl for IirFilter {
fn setup(&self, info: &gst_audio::AudioInfo) -> Result<(), gst::LoggableError> {
self.parent_setup(info)?;
gst::debug!(CAT, imp: self, "Rate changed to {}", info.rate());
gst::debug!(CAT, imp = self, "Rate changed to {}", info.rate());
let obj = self.obj();
(obj.class().as_ref().set_rate)(&obj, info.rate());
@ -177,7 +177,7 @@ impl AudioFilterImpl for IirFilter {
/// Wrappers for public methods and associated helper functions.
impl IirFilter {
pub(super) fn set_coeffs(&self, a: Vec<f64>, b: Vec<f64>) {
gst::debug!(CAT, imp: self, "Setting coefficients a: {a:?}, b: {b:?}");
gst::debug!(CAT, imp = self, "Setting coefficients a: {a:?}, b: {b:?}");
*self.coeffs.lock().unwrap() = Some((a, b));
}
}

View file

@ -308,7 +308,7 @@ pub trait BaseSrcImplExt: sealed::Sealed + ObjectSubclass {
if buffer_ptr.is_null() && pending_buffer_list.is_none() {
gst::error!(
gst::CAT_RUST,
obj: instance,
obj = instance,
"No buffer and no buffer list returned"
);
return Err(gst::FlowError::Error);
@ -317,7 +317,7 @@ pub trait BaseSrcImplExt: sealed::Sealed + ObjectSubclass {
if !buffer_ptr.is_null() && pending_buffer_list.is_some() {
gst::error!(
gst::CAT_RUST,
obj: instance,
obj = instance,
"Both buffer and buffer list returned"
);
return Err(gst::FlowError::Error);
@ -329,7 +329,7 @@ pub trait BaseSrcImplExt: sealed::Sealed + ObjectSubclass {
gst::debug!(
gst::CAT_PERFORMANCE,
obj: instance,
obj = instance,
"Returned new buffer from parent create function, copying into passed buffer"
);
@ -338,7 +338,7 @@ pub trait BaseSrcImplExt: sealed::Sealed + ObjectSubclass {
Err(_) => {
gst::error!(
gst::CAT_RUST,
obj: instance,
obj = instance,
"Failed to map passed buffer writable"
);
return Err(gst::FlowError::Error);
@ -357,7 +357,7 @@ pub trait BaseSrcImplExt: sealed::Sealed + ObjectSubclass {
Err(_) => {
gst::error!(
gst::CAT_RUST,
obj: instance,
obj = instance,
"Failed to copy buffer metadata"
);
@ -752,7 +752,7 @@ unsafe extern "C" fn base_src_create<T: BaseSrcImpl>(
if passed_buffer.as_ptr() != new_buffer.as_ptr() {
gst::debug!(
gst::CAT_PERFORMANCE,
obj: instance,
obj = instance,
"Returned new buffer from create function, copying into passed buffer"
);
@ -761,7 +761,7 @@ unsafe extern "C" fn base_src_create<T: BaseSrcImpl>(
Err(_) => {
gst::error!(
gst::CAT_RUST,
obj: instance,
obj = instance,
"Failed to map passed buffer writable"
);
return gst::FlowReturn::Error;
@ -780,7 +780,7 @@ unsafe extern "C" fn base_src_create<T: BaseSrcImpl>(
Err(_) => {
gst::error!(
gst::CAT_RUST,
obj: instance,
obj = instance,
"Failed to copy buffer metadata"
);

View file

@ -1215,7 +1215,7 @@ unsafe extern "C" fn base_transform_copy_metadata<T: BaseTransformImpl>(
if gst::ffi::gst_mini_object_is_writable(outbuf as *mut _) == glib::ffi::GFALSE {
let instance = imp.obj();
let obj = instance.unsafe_cast_ref::<BaseTransform>();
gst::warning!(gst::CAT_RUST, obj: obj, "buffer {:?} not writable", outbuf);
gst::warning!(gst::CAT_RUST, obj = obj, "buffer {:?} not writable", outbuf);
return glib::ffi::GFALSE;
}

View file

@ -110,7 +110,7 @@ pub trait PushSrcImplExt: sealed::Sealed + ObjectSubclass {
if buffer_ptr.is_null() && pending_buffer_list.is_none() {
gst::error!(
gst::CAT_RUST,
obj: instance,
obj = instance,
"No buffer and no buffer list returned"
);
return Err(gst::FlowError::Error);
@ -119,7 +119,7 @@ pub trait PushSrcImplExt: sealed::Sealed + ObjectSubclass {
if !buffer_ptr.is_null() && pending_buffer_list.is_some() {
gst::error!(
gst::CAT_RUST,
obj: instance,
obj = instance,
"Both buffer and buffer list returned"
);
return Err(gst::FlowError::Error);
@ -131,7 +131,7 @@ pub trait PushSrcImplExt: sealed::Sealed + ObjectSubclass {
gst::debug!(
gst::CAT_PERFORMANCE,
obj: instance,
obj = instance,
"Returned new buffer from parent create function, copying into passed buffer"
);
@ -140,7 +140,7 @@ pub trait PushSrcImplExt: sealed::Sealed + ObjectSubclass {
Err(_) => {
gst::error!(
gst::CAT_RUST,
obj: instance,
obj = instance,
"Failed to map passed buffer writable"
);
return Err(gst::FlowError::Error);
@ -159,7 +159,7 @@ pub trait PushSrcImplExt: sealed::Sealed + ObjectSubclass {
Err(_) => {
gst::error!(
gst::CAT_RUST,
obj: instance,
obj = instance,
"Failed to copy buffer metadata"
);
@ -259,7 +259,7 @@ unsafe extern "C" fn push_src_create<T: PushSrcImpl>(
if passed_buffer.as_ptr() != new_buffer.as_ptr() {
gst::debug!(
gst::CAT_PERFORMANCE,
imp: imp,
imp = imp,
"Returned new buffer from create function, copying into passed buffer"
);
@ -268,7 +268,7 @@ unsafe extern "C" fn push_src_create<T: PushSrcImpl>(
Err(_) => {
gst::error!(
gst::CAT_RUST,
imp: imp,
imp = imp,
"Failed to map passed buffer writable"
);
return gst::FlowReturn::Error;
@ -287,7 +287,7 @@ unsafe extern "C" fn push_src_create<T: PushSrcImpl>(
Err(_) => {
gst::error!(
gst::CAT_RUST,
imp: imp,
imp = imp,
"Failed to copy buffer metadata"
);

View file

@ -181,11 +181,23 @@ impl StreamProducer {
) -> Result<(), AddConsumerError> {
let mut consumers = self.consumers.lock().unwrap();
if consumers.consumers.contains_key(consumer) {
gst::error!(CAT, obj: &self.appsink, "Consumer {} ({:?}) already added", consumer.name(), consumer);
gst::error!(
CAT,
obj = &self.appsink,
"Consumer {} ({:?}) already added",
consumer.name(),
consumer
);
return Err(AddConsumerError::AlreadyAdded);
}
gst::debug!(CAT, obj: &self.appsink, "Adding consumer {} ({:?})", consumer.name(), consumer);
gst::debug!(
CAT,
obj = &self.appsink,
"Adding consumer {} ({:?})",
consumer.name(),
consumer
);
Self::configure_consumer(consumer);
@ -205,7 +217,7 @@ impl StreamProducer {
};
if gst_video::UpstreamForceKeyUnitEvent::parse(event).is_ok() {
gst::debug!(CAT, obj: &appsink, "Requesting keyframe");
gst::debug!(CAT, obj = &appsink, "Requesting keyframe");
// Do not use `gst_element_send_event()` as it takes the state lock which may lead to dead locks.
let pad = appsink.static_pad("sink").unwrap();
let _ = pad.push_event(event.clone());
@ -232,7 +244,7 @@ impl StreamProducer {
let appsink_pad = self.appsink.static_pad("sink").unwrap();
appsink_pad.sticky_events_foreach(|event| {
if events_to_forward.contains(&event.type_()) {
gst::debug!(CAT, obj: &self.appsink, "forward sticky event {:?}", event);
gst::debug!(CAT, obj = &self.appsink, "forward sticky event {:?}", event);
consumer.send_event(event.clone());
}
@ -258,7 +270,12 @@ impl StreamProducer {
(false, true)
};
gst::trace!(CAT, obj: appsink, "processing sample {:?}", sample.buffer());
gst::trace!(
CAT,
obj = appsink,
"processing sample {:?}",
sample.buffer()
);
let latency = consumers.current_latency;
let latency_updated = mem::replace(&mut consumers.latency_updated, false);
@ -302,7 +319,7 @@ impl StreamProducer {
if !is_keyframe && consumer.needs_keyframe.load(atomic::Ordering::SeqCst) {
// If we need a keyframe (and this one isn't) request a keyframe upstream
if !needs_keyframe_request {
gst::debug!(CAT, obj: appsink, "Requesting keyframe for first buffer");
gst::debug!(CAT, obj = appsink, "Requesting keyframe for first buffer");
needs_keyframe_request = true;
}
@ -310,7 +327,7 @@ impl StreamProducer {
gst::debug!(
CAT,
obj: appsink,
obj = appsink,
"Ignoring frame for {} while waiting for a keyframe",
consumer.appsrc.name()
);
@ -340,7 +357,7 @@ impl StreamProducer {
for consumer in current_consumers {
if let Err(err) = consumer.push_sample(&sample) {
gst::warning!(CAT, obj: appsink, "Failed to push sample: {}", err);
gst::warning!(CAT, obj = appsink, "Failed to push sample: {}", err);
}
}
Ok(gst::FlowSuccess::Ok)
@ -357,10 +374,22 @@ impl StreamProducer {
.remove(consumer)
.is_some()
{
gst::debug!(CAT, obj: &self.appsink, "Removed consumer {} ({:?})", name, consumer);
gst::debug!(
CAT,
obj = &self.appsink,
"Removed consumer {} ({:?})",
name,
consumer
);
consumer.set_callbacks(gst_app::AppSrcCallbacks::builder().build());
} else {
gst::debug!(CAT, obj: &self.appsink, "Consumer {} ({:?}) not found", name, consumer);
gst::debug!(
CAT,
obj = &self.appsink,
"Consumer {} ({:?}) not found",
name,
consumer
);
}
}
@ -415,32 +444,40 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
appsink.set_callbacks(
gst_app::AppSinkCallbacks::builder()
.new_sample(glib::clone!(#[strong] consumers, move |appsink| {
.new_sample(glib::clone!(
#[strong]
consumers,
move |appsink| {
let mut consumers = consumers.lock().unwrap();
let sample = match appsink.pull_sample() {
Ok(sample) => sample,
Err(_err) => {
gst::debug!(CAT, obj: appsink, "Failed to pull sample");
gst::debug!(CAT, obj = appsink, "Failed to pull sample");
return Err(gst::FlowError::Flushing);
}
};
let just_forwarded_preroll = mem::replace(&mut consumers.just_forwarded_preroll, false);
let just_forwarded_preroll =
mem::replace(&mut consumers.just_forwarded_preroll, false);
if just_forwarded_preroll {
return Ok(gst::FlowSuccess::Ok);
}
StreamProducer::process_sample(sample, appsink, consumers)
}))
.new_preroll(glib::clone!(#[strong] consumers, move |appsink| {
}
))
.new_preroll(glib::clone!(
#[strong]
consumers,
move |appsink| {
let mut consumers = consumers.lock().unwrap();
let sample = match appsink.pull_preroll() {
Ok(sample) => sample,
Err(_err) => {
gst::debug!(CAT, obj: appsink, "Failed to pull preroll");
gst::debug!(CAT, obj = appsink, "Failed to pull preroll");
return Err(gst::FlowError::Flushing);
}
};
@ -452,15 +489,23 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
} else {
Ok(gst::FlowSuccess::Ok)
}
}))
.new_event(glib::clone!(#[strong] consumers, move |appsink| {
match appsink.pull_object().map(|obj| obj.downcast::<gst::Event>()) {
}
))
.new_event(glib::clone!(
#[strong]
consumers,
move |appsink| {
match appsink
.pull_object()
.map(|obj| obj.downcast::<gst::Event>())
{
Ok(Ok(event)) => {
let (events_to_forward, appsrcs) = {
// clone so we don't keep the lock while pushing events
let consumers = consumers.lock().unwrap();
let events = consumers.events_to_forward.clone();
let appsrcs = consumers.consumers.keys().cloned().collect::<Vec<_>>();
let appsrcs =
consumers.consumers.keys().cloned().collect::<Vec<_>>();
(events, appsrcs)
};
@ -471,18 +516,23 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
}
}
}
Ok(Err(_)) => {}, // pulled another unsupported object type, ignore
Err(_err) => gst::warning!(CAT, obj: appsink, "Failed to pull event"),
Ok(Err(_)) => {} // pulled another unsupported object type, ignore
Err(_err) => gst::warning!(CAT, obj = appsink, "Failed to pull event"),
}
false
}))
.eos(glib::clone!(#[strong] consumers, move |appsink| {
let stream_consumers = consumers
.lock()
.unwrap();
}
))
.eos(glib::clone!(
#[strong]
consumers,
move |appsink| {
let stream_consumers = consumers.lock().unwrap();
if stream_consumers.events_to_forward.contains(&gst::EventType::Eos) {
if stream_consumers
.events_to_forward
.contains(&gst::EventType::Eos)
{
let current_consumers = stream_consumers
.consumers
.values()
@ -491,13 +541,19 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
drop(stream_consumers);
for consumer in current_consumers {
gst::debug!(CAT, obj: appsink, "set EOS on consumer {}", consumer.name());
gst::debug!(
CAT,
obj = appsink,
"set EOS on consumer {}",
consumer.name()
);
let _ = consumer.end_of_stream();
}
} else {
gst::debug!(CAT, obj: appsink, "don't forward EOS to consumers");
gst::debug!(CAT, obj = appsink, "don't forward EOS to consumers");
}
}))
}
))
.build(),
);
@ -591,7 +647,7 @@ impl StreamConsumer {
.enough_data(move |appsrc| {
gst::debug!(
CAT,
obj: appsrc,
obj = appsrc,
"consumer {} ({:?}) is not consuming fast enough, old samples are getting dropped",
appsrc.name(),
appsrc,

View file

@ -304,7 +304,7 @@ impl<'a> ElementBuilder<'a> {
let factory = factory.load().map_err(|_| {
crate::warning!(
crate::CAT_RUST,
obj: factory,
obj = factory,
"loading element factory '{}' failed",
factory.name(),
);
@ -318,7 +318,7 @@ impl<'a> ElementBuilder<'a> {
if !element_type.is_valid() {
crate::warning!(
crate::CAT_RUST,
obj: &factory,
obj = &factory,
"element factory '{}' has no type",
factory.name()
);
@ -422,7 +422,7 @@ impl<'a> ElementBuilder<'a> {
crate::log!(
crate::CAT_RUST,
obj: &factory,
obj = &factory,
"created element \"{}\"",
factory.name()
);

View file

@ -613,135 +613,383 @@ declare_debug_category_from_name!(CAT_CONTEXT, "GST_CONTEXT");
#[macro_export]
macro_rules! error(
($cat:expr, obj = $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Error, obj = $obj, $($args)*)
}};
($cat:expr, imp = $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Error, imp = $imp, $($args)*)
}};
($cat:expr, id = $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Error, id = $id, $($args)*)
}};
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Error, obj: $obj, $($args)*)
{
#[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"]
macro_rules! error(
() => {}
);
error!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Error, obj = $obj, $($args)*)
}};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Error, imp: $imp, $($args)*)
{
#[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"]
macro_rules! error(
() => {}
);
error!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Error, imp = $imp, $($args)*)
}};
($cat:expr, id: $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Error, id: $id, $($args)*)
{
#[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"]
macro_rules! error(
() => {}
);
error!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Error, id = $id, $($args)*)
}};
($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Error, $($args)*)
$crate::log_with_level!($cat, $crate::DebugLevel::Error, $($args)*)
}};
);
#[macro_export]
macro_rules! warning(
($cat:expr, obj = $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Warning, obj = $obj, $($args)*)
}};
($cat:expr, imp = $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Warning, imp = $imp, $($args)*)
}};
($cat:expr, id = $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Warning, id = $id, $($args)*)
}};
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Warning, obj: $obj, $($args)*)
{
#[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"]
macro_rules! warning(
() => {}
);
warning!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Warning, obj = $obj, $($args)*)
}};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Warning, imp: $imp, $($args)*)
{
#[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"]
macro_rules! warning(
() => {}
);
warning!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Warning, imp = $imp, $($args)*)
}};
($cat:expr, id: $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Warning, id: $id, $($args)*)
{
#[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"]
macro_rules! warning(
() => {}
);
warning!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Warning, id = $id, $($args)*)
}};
($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Warning, $($args)*)
$crate::log_with_level!($cat, $crate::DebugLevel::Warning, $($args)*)
}};
);
#[macro_export]
macro_rules! fixme(
($cat:expr, obj = $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Fixme, obj = $obj, $($args)*)
}};
($cat:expr, imp = $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Fixme, imp = $imp, $($args)*)
}};
($cat:expr, id = $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Fixme, id = $id, $($args)*)
}};
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Fixme, obj: $obj, $($args)*)
{
#[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"]
macro_rules! fixme(
() => {}
);
fixme!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Fixme, obj = $obj, $($args)*)
}};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Fixme, imp: $imp, $($args)*)
{
#[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"]
macro_rules! fixme(
() => {}
);
fixme!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Fixme, imp = $imp, $($args)*)
}};
($cat:expr, id: $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Fixme, id: $id, $($args)*)
{
#[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"]
macro_rules! fixme(
() => {}
);
fixme!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Fixme, id = $id, $($args)*)
}};
($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Fixme, $($args)*)
$crate::log_with_level!($cat, $crate::DebugLevel::Fixme, $($args)*)
}};
);
#[macro_export]
macro_rules! info(
($cat:expr, obj = $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Info, obj = $obj, $($args)*)
}};
($cat:expr, imp = $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Info, imp = $imp, $($args)*)
}};
($cat:expr, id = $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Info, id = $id, $($args)*)
}};
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Info, obj: $obj, $($args)*)
{
#[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"]
macro_rules! info(
() => {}
);
info!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Info, obj = $obj, $($args)*)
}};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Info, imp: $imp, $($args)*)
{
#[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"]
macro_rules! info(
() => {}
);
info!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Info, imp = $imp, $($args)*)
}};
($cat:expr, id: $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Info, id: $id, $($args)*)
{
#[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"]
macro_rules! info(
() => {}
);
info!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Info, id = $id, $($args)*)
}};
($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Info, $($args)*)
$crate::log_with_level!($cat, $crate::DebugLevel::Info, $($args)*)
}};
);
#[macro_export]
macro_rules! debug(
($cat:expr, obj = $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Debug, obj = $obj, $($args)*)
}};
($cat:expr, imp = $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Debug, imp = $imp, $($args)*)
}};
($cat:expr, id = $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Debug, id = $id, $($args)*)
}};
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Debug, obj: $obj, $($args)*)
{
#[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"]
macro_rules! debug(
() => {}
);
debug!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Debug, obj = $obj, $($args)*)
}};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Debug, imp: $imp, $($args)*)
{
#[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"]
macro_rules! debug(
() => {}
);
debug!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Debug, imp = $imp, $($args)*)
}};
($cat:expr, id: $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Debug, id: $id, $($args)*)
{
#[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"]
macro_rules! debug(
() => {}
);
debug!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Debug, id = $id, $($args)*)
}};
($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Debug, $($args)*)
$crate::log_with_level!($cat, $crate::DebugLevel::Debug, $($args)*)
}};
);
#[macro_export]
macro_rules! log(
($cat:expr, obj = $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Log, obj = $obj, $($args)*)
}};
($cat:expr, imp = $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Log, imp = $imp, $($args)*)
}};
($cat:expr, id = $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Log, id = $id, $($args)*)
}};
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Log, obj: $obj, $($args)*)
{
#[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"]
macro_rules! log(
() => {}
);
log!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Log, obj = $obj, $($args)*)
}};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Log, imp: $imp, $($args)*)
{
#[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"]
macro_rules! log(
() => {}
);
log!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Log, imp = $imp, $($args)*)
}};
($cat:expr, id: $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Log, id: $id, $($args)*)
{
#[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"]
macro_rules! log(
() => {}
);
log!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Log, id = $id, $($args)*)
}};
($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Log, $($args)*)
$crate::log_with_level!($cat, $crate::DebugLevel::Log, $($args)*)
}};
);
#[macro_export]
macro_rules! trace(
($cat:expr, obj = $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Trace, obj = $obj, $($args)*)
}};
($cat:expr, imp = $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Trace, imp = $imp, $($args)*)
}};
($cat:expr, id = $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Trace, id = $id, $($args)*)
}};
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Trace, obj: $obj, $($args)*)
{
#[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"]
macro_rules! trace(
() => {}
);
trace!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Trace, obj = $obj, $($args)*)
}};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Trace, imp: $imp, $($args)*)
{
#[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"]
macro_rules! trace(
() => {}
);
trace!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Trace, imp = $imp, $($args)*)
}};
($cat:expr, id: $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Trace, id: $id, $($args)*)
{
#[deprecated = "Using old-style id format. Use `id = ` instead of `id: `"]
macro_rules! trace(
() => {}
);
trace!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Trace, id = $id, $($args)*)
}};
($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Trace, $($args)*)
$crate::log_with_level!($cat, $crate::DebugLevel::Trace, $($args)*)
}};
);
#[macro_export]
macro_rules! memdump(
($cat:expr, obj = $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Memdump, obj = $obj, $($args)*)
}};
($cat:expr, imp = $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Memdump, imp = $imp, $($args)*)
}};
($cat:expr, id = $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, $crate::DebugLevel::Memdump, id = $id, $($args)*)
}};
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Memdump, obj: $obj, $($args)*)
{
#[deprecated = "Using old-style obj format. Use `obj = ` instead of `obj: ` for better tooling support"]
macro_rules! memdump(
() => {}
);
memdump!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Memdump, obj = $obj, $($args)*)
}};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Memdump, imp: $imp, $($args)*)
{
#[deprecated = "Using old-style imp format. Use `imp = ` instead of `imp: ` for better tooling support"]
macro_rules! memdump(
() => {}
);
memdump!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Memdump, imp = $imp, $($args)*)
}};
($cat:expr, id: $id:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Memdump, id: $id, $($args)*)
{
#[deprecated = "Using old-style id format. Use `id = ` instead of `id: ` for better tooling support"]
macro_rules! memdump(
() => {}
);
memdump!();
}
$crate::log_with_level!($cat, $crate::DebugLevel::Memdump, id = $id, $($args)*)
}};
($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat, level: $crate::DebugLevel::Memdump, $($args)*)
$crate::log_with_level!($cat, $crate::DebugLevel::Memdump, $($args)*)
}};
);
#[macro_export]
macro_rules! log_with_level(
($cat:expr, level: $level:expr, obj: $obj:expr, $msg:literal) => { {
($cat:expr, $level:expr, obj = $obj:expr, $msg:literal) => { {
let cat = $cat.clone();
// Check the log level before using `format_args!` otherwise
@ -785,7 +1033,7 @@ macro_rules! log_with_level(
})(format_args!($msg))
}
}};
($cat:expr, level: $level:expr, obj: $obj:expr, $($args:tt)*) => { {
($cat:expr, $level:expr, obj = $obj:expr, $($args:tt)*) => { {
let cat = $cat.clone();
// Check the log level before using `format_args!` otherwise
@ -809,7 +1057,7 @@ macro_rules! log_with_level(
)
}
}};
($cat:expr, level: $level:expr, imp: $imp:expr, $msg:literal) => { {
($cat:expr, $level:expr, imp = $imp:expr, $msg:literal) => { {
let cat = $cat.clone();
// Check the log level before using `format_args!` otherwise
@ -854,7 +1102,7 @@ macro_rules! log_with_level(
})(format_args!($msg))
}
}};
($cat:expr, level: $level:expr, imp: $imp:expr, $($args:tt)*) => { {
($cat:expr, $level:expr, imp = $imp:expr, $($args:tt)*) => { {
let cat = $cat.clone();
// Check the log level before using `format_args!` otherwise
@ -879,7 +1127,7 @@ macro_rules! log_with_level(
)
}
}};
($cat:expr, level: $level:expr, id: $id:literal, $msg:literal) => { {
($cat:expr, $level:expr, id = $id:literal, $msg:literal) => { {
let cat = $cat.clone();
// Check the log level before using `format_args!` otherwise
@ -920,7 +1168,7 @@ macro_rules! log_with_level(
})(format_args!($msg))
}
}};
($cat:expr, level: $level:expr, id: $id:literal, $($args:tt)*) => { {
($cat:expr, $level:expr, id = $id:literal, $($args:tt)*) => { {
let cat = $cat.clone();
// Check the log level before using `format_args!` otherwise
@ -941,7 +1189,7 @@ macro_rules! log_with_level(
)
}
}};
($cat:expr, level: $level:expr, id: $id:expr, $msg:literal) => { {
($cat:expr, $level:expr, id = $id:expr, $msg:literal) => { {
let cat = $cat.clone();
// Check the log level before using `format_args!` otherwise
@ -982,7 +1230,7 @@ macro_rules! log_with_level(
})(format_args!($msg))
}
}};
($cat:expr, level: $level:expr, id: $id:expr, $($args:tt)*) => { {
($cat:expr, $level:expr, id = $id:expr, $($args:tt)*) => { {
let cat = $cat.clone();
// Check the log level before using `format_args!` otherwise
@ -1003,7 +1251,7 @@ macro_rules! log_with_level(
)
}
}};
($cat:expr, level: $level:expr, $msg:literal) => { {
($cat:expr, $level:expr, $msg:literal) => { {
let cat = $cat.clone();
// Check the log level before using `format_args!` otherwise
@ -1044,7 +1292,7 @@ macro_rules! log_with_level(
})(format_args!($msg))
}
}};
($cat:expr, level: $level:expr, $($args:tt)*) => { {
($cat:expr, $level:expr, $($args:tt)*) => { {
let cat = $cat.clone();
// Check the log level before using `format_args!` otherwise
@ -1343,23 +1591,23 @@ mod tests {
let obj = crate::Bin::with_name("meh");
error!(cat, obj: &obj, "meh");
warning!(cat, obj: &obj, "meh");
fixme!(cat, obj: &obj, "meh");
info!(cat, obj: &obj, "meh");
debug!(cat, obj: &obj, "meh");
log!(cat, obj: &obj, "meh");
trace!(cat, obj: &obj, "meh");
memdump!(cat, obj: &obj, "meh");
error!(cat, obj = &obj, "meh");
warning!(cat, obj = &obj, "meh");
fixme!(cat, obj = &obj, "meh");
info!(cat, obj = &obj, "meh");
debug!(cat, obj = &obj, "meh");
log!(cat, obj = &obj, "meh");
trace!(cat, obj = &obj, "meh");
memdump!(cat, obj = &obj, "meh");
error!(cat, obj: obj, "meh");
warning!(cat, obj: obj, "meh");
fixme!(cat, obj: obj, "meh");
info!(cat, obj: obj, "meh");
debug!(cat, obj: obj, "meh");
log!(cat, obj: obj, "meh");
trace!(cat, obj: obj, "meh");
memdump!(cat, obj: obj, "meh");
error!(cat, obj = obj, "meh");
warning!(cat, obj = obj, "meh");
fixme!(cat, obj = obj, "meh");
info!(cat, obj = obj, "meh");
debug!(cat, obj = obj, "meh");
log!(cat, obj = obj, "meh");
trace!(cat, obj = obj, "meh");
memdump!(cat, obj = obj, "meh");
}
#[cfg(feature = "log")]
@ -1459,13 +1707,13 @@ mod tests {
remove_default_log_function();
let log_fn = add_log_function(handler);
info!(cat, obj: &obj, "meh");
info!(cat, obj = &obj, "meh");
receiver.recv().unwrap();
remove_log_function(log_fn);
info!(cat, obj: &obj, "meh2");
info!(cat, obj = &obj, "meh2");
assert!(receiver.recv().is_err());
}
@ -1501,12 +1749,12 @@ mod tests {
cat.set_threshold(crate::DebugLevel::Trace);
trace!(cat, id: "123", "test");
trace!(cat, id: glib::GString::from("123"), "test");
trace!(cat, id: &glib::GString::from("123"), "test");
trace!(cat, id = "123", "test");
trace!(cat, id = glib::GString::from("123"), "test");
trace!(cat, id = &glib::GString::from("123"), "test");
// Try with a formatted string too (which is a different code path in the bindings)
let log_id = glib::GString::from("456");
trace!(cat, id: &log_id , "{log_id:?}");
trace!(cat, id = &log_id, "{log_id:?}");
}
}

View file

@ -1277,7 +1277,7 @@ where
if let Some(passed_buffer) = passed_buffer {
crate::debug!(
crate::CAT_PERFORMANCE,
obj: pad.unsafe_cast_ref::<glib::Object>(),
obj = pad.unsafe_cast_ref::<glib::Object>(),
"Returned new buffer from getrange function, copying into passed buffer"
);
@ -1286,7 +1286,7 @@ where
Err(_) => {
crate::error!(
crate::CAT_RUST,
obj: pad.unsafe_cast_ref::<glib::Object>(),
obj = pad.unsafe_cast_ref::<glib::Object>(),
"Failed to map passed buffer writable"
);
return ffi::GST_FLOW_ERROR;
@ -1305,7 +1305,7 @@ where
Err(_) => {
crate::error!(
crate::CAT_RUST,
obj: pad.unsafe_cast_ref::<glib::Object>(),
obj = pad.unsafe_cast_ref::<glib::Object>(),
"Failed to copy buffer metadata"
);

View file

@ -89,7 +89,7 @@ unsafe extern "C" fn alloc<T: AllocatorImpl>(
imp.alloc(size, params)
.map(|memory| memory.into_glib_ptr())
.unwrap_or_else(|error| {
error!(crate::CAT_RUST, obj: instance, "{:?}", error);
error!(crate::CAT_RUST, obj = instance, "{:?}", error);
ptr::null_mut()
})

View file

@ -111,7 +111,11 @@ unsafe extern "C" fn task_pool_push<T: TaskPoolImpl>(
unsafe extern "C" fn task_pool_join<T: TaskPoolImpl>(ptr: *mut ffi::GstTaskPool, id: gpointer) {
if id.is_null() {
let wrap: Borrowed<TaskPool> = from_glib_borrow(ptr);
crate::warning!(crate::CAT_RUST, obj: wrap.as_ref(), "Tried to join null handle");
crate::warning!(
crate::CAT_RUST,
obj = wrap.as_ref(),
"Tried to join null handle"
);
return;
}
@ -127,7 +131,11 @@ unsafe extern "C" fn task_pool_dispose_handle<T: TaskPoolImpl>(
) {
if id.is_null() {
let wrap: Borrowed<TaskPool> = from_glib_borrow(ptr);
crate::warning!(crate::CAT_RUST, obj: wrap.as_ref(), "Tried to dispose null handle");
crate::warning!(
crate::CAT_RUST,
obj = wrap.as_ref(),
"Tried to dispose null handle"
);
return;
}

View file

@ -114,7 +114,7 @@ impl Drop for TaskPoolTaskHandle {
if #[cfg(feature = "v1_20")] {
unsafe { task_pool.dispose_handle(self.handle) }
} else {
crate::warning!(crate::CAT_RUST, obj: &task_pool, "Leaked task handle");
crate::warning!(crate::CAT_RUST, obj = &task_pool, "Leaked task handle");
}
}
}