Skip to content

Commit cdc3212

Browse files
Mododohds
andauthored
tracing: fix "name / parent" variant of event! (#2983)
## Motivation In the case of an event with a name and a parent, the change in #2083 to use a free function instead of a method for `is_enabled` was not applied. This particular variant was also not covered by any tests, which is how this error slipped through CI. ## Solution This change fixes the `is_enabled` call and adds additional test coverage for this macros case. Co-authored-by: Hayden Stainsby <hds@caffeineconcepts.com>
1 parent 656a7c9 commit cdc3212

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

tracing/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ macro_rules! event {
789789

790790
let enabled = $crate::level_enabled!($lvl) && {
791791
let interest = __CALLSITE.interest();
792-
!interest.is_never() && __CALLSITE.is_enabled(interest)
792+
!interest.is_never() && $crate::__macro_support::__is_enabled(__CALLSITE.metadata(), interest)
793793
};
794794
if enabled {
795795
(|value_set: $crate::field::ValueSet| {

tracing/tests/macros.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,13 @@ fn locals_no_message() {
526526
private_data,
527527
?data,
528528
);
529+
event!(
530+
name: "foo",
531+
parent: ::core::option::Option::None,
532+
Level::WARN,
533+
private_data,
534+
?data,
535+
);
529536
event!(
530537
target: "app_events",
531538
Level::WARN,
@@ -570,6 +577,7 @@ fn trace() {
570577
trace!({ foo = ?2, bar.baz = %78 }, "quux");
571578
trace!(name: "foo", foo = 3, bar.baz = 2, quux = false);
572579
trace!(name: "foo", target: "foo_events", foo = 3, bar.baz = 2, quux = false);
580+
trace!(name: "foo", parent: ::core::option::Option::None, foo = 3, bar.baz = 2, quux = false);
573581
trace!(target: "foo_events", foo = 3, bar.baz = 2, quux = false);
574582
trace!(target: "foo_events", foo = 3, bar.baz = 3,);
575583
trace!(target: "foo_events", "foo");
@@ -636,6 +644,7 @@ fn debug() {
636644
debug!({ foo = ?2, bar.baz = %78 }, "quux");
637645
debug!(name: "foo", foo = 3, bar.baz = 2, quux = false);
638646
debug!(name: "foo", target: "foo_events", foo = 3, bar.baz = 2, quux = false);
647+
debug!(name: "foo", parent: ::core::option::Option::None, foo = 3, bar.baz = 2, quux = false);
639648
debug!(target: "foo_events", foo = 3, bar.baz = 2, quux = false);
640649
debug!(target: "foo_events", foo = 3, bar.baz = 3,);
641650
debug!(target: "foo_events", "foo");
@@ -702,6 +711,7 @@ fn info() {
702711
info!({ foo = ?2, bar.baz = %78 }, "quux");
703712
info!(name: "foo", foo = 3, bar.baz = 2, quux = false);
704713
info!(name: "foo", target: "foo_events", foo = 3, bar.baz = 2, quux = false);
714+
info!(name: "foo", parent: ::core::option::Option::None, foo = 3, bar.baz = 2, quux = false);
705715
info!(target: "foo_events", foo = 3, bar.baz = 2, quux = false);
706716
info!(target: "foo_events", foo = 3, bar.baz = 3,);
707717
info!(target: "foo_events", "foo");
@@ -768,6 +778,7 @@ fn warn() {
768778
warn!({ foo = ?2, bar.baz = %78 }, "quux");
769779
warn!(name: "foo", foo = 3, bar.baz = 2, quux = false);
770780
warn!(name: "foo", target: "foo_events", foo = 3, bar.baz = 2, quux = false);
781+
warn!(name: "foo", parent: ::core::option::Option::None, foo = 3, bar.baz = 2, quux = false);
771782
warn!(target: "foo_events", foo = 3, bar.baz = 2, quux = false);
772783
warn!(target: "foo_events", foo = 3, bar.baz = 3,);
773784
warn!(target: "foo_events", "foo");
@@ -834,6 +845,7 @@ fn error() {
834845
error!({ foo = ?2, bar.baz = %78 }, "quux");
835846
error!(name: "foo", foo = 3, bar.baz = 2, quux = false);
836847
error!(name: "foo", target: "foo_events", foo = 3, bar.baz = 2, quux = false);
848+
error!(name: "foo", parent: ::core::option::Option::None, foo = 3, bar.baz = 2, quux = false);
837849
error!(target: "foo_events", foo = 3, bar.baz = 2, quux = false);
838850
error!(target: "foo_events", foo = 3, bar.baz = 3,);
839851
error!(target: "foo_events", "foo");

0 commit comments

Comments
 (0)