From c0a63b5c81e808573c960826d6548eb0b0dcbbc4 Mon Sep 17 00:00:00 2001 From: Aaron Roney Date: Mon, 28 Aug 2023 16:28:58 -0700 Subject: [PATCH 1/7] Allow setting event names in macros. --- tracing/src/macros.rs | 761 +++++++++++++++++++++++++++++++++++----- tracing/tests/macros.rs | 143 ++++++++ 2 files changed, 825 insertions(+), 79 deletions(-) diff --git a/tracing/src/macros.rs b/tracing/src/macros.rs index f47f9bbb2b..3640af62a4 100644 --- a/tracing/src/macros.rs +++ b/tracing/src/macros.rs @@ -583,6 +583,112 @@ macro_rules! error_span { // /// ``` #[macro_export] macro_rules! event { + // Name / target / parent. + (name: $name:expr, target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ + use $crate::__macro_support::Callsite as _; + static CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! { + name: $name, + kind: $crate::metadata::Kind::EVENT, + target: $target, + level: $lvl, + fields: $($fields)* + }; + + let enabled = $crate::level_enabled!($lvl) && { + let interest = CALLSITE.interest(); + !interest.is_never() && CALLSITE.is_enabled(interest) + }; + if enabled { + (|value_set: $crate::field::ValueSet| { + $crate::__tracing_log!( + $lvl, + CALLSITE, + &value_set + ); + let meta = CALLSITE.metadata(); + // event with explicit parent + $crate::Event::child_of( + $parent, + meta, + &value_set + ); + })($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); + } else { + $crate::__tracing_log!( + $lvl, + CALLSITE, + &$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*) + ); + } + }); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + name: $name, + target: $target, + parent: $parent, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $lvl, { $($arg)+ }) + ); + + // Name / target. + (name: $name:expr, target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ + use $crate::__macro_support::Callsite as _; + static CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! { + name: $name, + kind: $crate::metadata::Kind::EVENT, + target: $target, + level: $lvl, + fields: $($fields)* + }; + let enabled = $crate::level_enabled!($lvl) && { + let interest = CALLSITE.interest(); + !interest.is_never() && CALLSITE.is_enabled(interest) + }; + if enabled { + (|value_set: $crate::field::ValueSet| { + let meta = CALLSITE.metadata(); + // event with contextual parent + $crate::Event::dispatch( + meta, + &value_set + ); + $crate::__tracing_log!( + $lvl, + CALLSITE, + &value_set + ); + })($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); + } else { + $crate::__tracing_log!( + $lvl, + CALLSITE, + &$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*) + ); + } + }); + (name: $name:expr, target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + name: $name, + target: $target, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + (name: $name:expr, target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::event!(name: $name, target: $target, $lvl, { $($k).+ = $($fields)* }) + ); + (name: $name:expr, target: $target:expr, $lvl:expr, $($arg:tt)+) => ( + $crate::event!(name: $name, target: $target, $lvl, { $($arg)+ }) + ); + + // Target / parent. (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ use $crate::__macro_support::Callsite as _; static CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! { @@ -625,7 +731,6 @@ macro_rules! event { ); } }); - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( $crate::event!( target: $target, @@ -640,6 +745,111 @@ macro_rules! event { (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( $crate::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) ); + + // Name / parent. + (name: $name:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ + use $crate::__macro_support::Callsite as _; + static CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! { + name: $name, + kind: $crate::metadata::Kind::EVENT, + target: module_path!(), + level: $lvl, + fields: $($fields)* + }; + + let enabled = $crate::level_enabled!($lvl) && { + let interest = CALLSITE.interest(); + !interest.is_never() && CALLSITE.is_enabled(interest) + }; + if enabled { + (|value_set: $crate::field::ValueSet| { + $crate::__tracing_log!( + $lvl, + CALLSITE, + &value_set + ); + let meta = CALLSITE.metadata(); + // event with explicit parent + $crate::Event::child_of( + $parent, + meta, + &value_set + ); + })($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); + } else { + $crate::__tracing_log!( + $lvl, + CALLSITE, + &$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*) + ); + } + }); + (name: $name:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + name: $name, + parent: $parent, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + (name: $name:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::event!(name: $name, parent: $parent, $lvl, { $($k).+ = $($fields)* }) + ); + (name: $name:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( + $crate::event!(name: $name, parent: $parent, $lvl, { $($arg)+ }) + ); + + // Name. + (name: $name:expr, $lvl:expr, { $($fields:tt)* } )=> ({ + use $crate::__macro_support::Callsite as _; + static CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! { + name: $name, + kind: $crate::metadata::Kind::EVENT, + target: module_path!(), + level: $lvl, + fields: $($fields)* + }; + let enabled = $crate::level_enabled!($lvl) && { + let interest = CALLSITE.interest(); + !interest.is_never() && CALLSITE.is_enabled(interest) + }; + if enabled { + (|value_set: $crate::field::ValueSet| { + let meta = CALLSITE.metadata(); + // event with contextual parent + $crate::Event::dispatch( + meta, + &value_set + ); + $crate::__tracing_log!( + $lvl, + CALLSITE, + &value_set + ); + })($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); + } else { + $crate::__tracing_log!( + $lvl, + CALLSITE, + &$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*) + ); + } + }); + (name: $name:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + name: $name, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + (name: $name:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::event!(name: $name, $lvl, { $($k).+ = $($fields)* }) + ); + (name: $name:expr, $lvl:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, $lvl, { $($arg)+ }) + ); + + // Target. (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ use $crate::__macro_support::Callsite as _; static CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! { @@ -693,6 +903,8 @@ macro_rules! event { (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( $crate::event!(target: $target, $lvl, { $($arg)+ }) ); + + // Parent. (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -752,6 +964,8 @@ macro_rules! event { (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( $crate::event!(target: module_path!(), parent: $parent, $lvl, { $($arg)+ }) ); + + // ... ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1083,6 +1297,41 @@ macro_rules! enabled { /// ``` #[macro_export] macro_rules! trace { + // Name / target / parent. + (name: $name:expr, target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) + ); + + // Name / target. + (name: $name:expr, target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*) + ); + (name: $name:expr, target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::TRACE, {}, $($arg)+) + ); + + // Target / parent. (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) ); @@ -1098,6 +1347,59 @@ macro_rules! trace { (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) ); + + // Name / parent. + (name: $name:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) + ); + (name: $name:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) + ); + + // Name. + (name: $name:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::TRACE, { $($field)* }, $($arg)*) + ); + (name: $name:expr, $($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::TRACE, { $($k).+ $($field)* }) + ); + (name: $name:expr, ?$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::TRACE, { ?$($k).+ $($field)* }) + ); + (name: $name:expr, %$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::TRACE, { %$($k).+ $($field)* }) + ); + (name: $name:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, $crate::Level::TRACE, {}, $($arg)+) + ); + + // Target. + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)* }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { ?$($k).+ $($field)* }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { %$($k).+ $($field)* }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, {}, $($arg)+) + ); + + // Parent. (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1164,21 +1466,8 @@ macro_rules! trace { $($arg)+ ) ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)* }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { ?$($k).+ $($field)* }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { %$($k).+ $($field)* }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, {}, $($arg)+) - ); + + // ... ({ $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1194,6 +1483,20 @@ macro_rules! trace { { $($k).+ = $($field)*} ) ); + (?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { ?$($k).+ = $($field)*} + ) + ); + (%$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { %$($k).+ = $($field)*} + ) + ); ($($k:ident).+, $($field:tt)*) => ( $crate::event!( target: module_path!(), @@ -1270,6 +1573,41 @@ macro_rules! trace { /// ``` #[macro_export] macro_rules! debug { + // Name / target / parent. + (name: $name:expr, target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) + ); + + // Name / target. + (name: $name:expr, target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*) + ); + (name: $name:expr, target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::DEBUG, {}, $($arg)+) + ); + + // Target / parent. (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) ); @@ -1285,6 +1623,59 @@ macro_rules! debug { (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) ); + + // Name / parent. + (name: $name:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) + ); + (name: $name:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) + ); + + // Name. + (name: $name:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::DEBUG, { $($field)* }, $($arg)*) + ); + (name: $name:expr, $($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::DEBUG, { $($k).+ $($field)* }) + ); + (name: $name:expr, ?$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::DEBUG, { ?$($k).+ $($field)* }) + ); + (name: $name:expr, %$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::DEBUG, { %$($k).+ $($field)* }) + ); + (name: $name:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, $crate::Level::DEBUG, {}, $($arg)+) + ); + + // Target. + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)* }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { ?$($k).+ $($field)* }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { %$($k).+ $($field)* }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, {}, $($arg)+) + ); + + // Parent. (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1351,21 +1742,8 @@ macro_rules! debug { $($arg)+ ) ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)* }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { ?$($k).+ $($field)* }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { %$($k).+ $($field)* }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, {}, $($arg)+) - ); + + // ... ({ $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1482,7 +1860,42 @@ macro_rules! debug { /// ``` #[macro_export] macro_rules! info { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + // Name / target / parent. + (name: $name:expr, target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+) + ); + + // Name / target. + (name: $name:expr, target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*) + ); + (name: $name:expr, target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::INFO, {}, $($arg)+) + ); + + // Target / parent. + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) ); (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( @@ -1497,6 +1910,59 @@ macro_rules! info { (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+) ); + + // Name / parent. + (name: $name:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) + ); + (name: $name:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::INFO, {}, $($arg)+) + ); + + // Name. + (name: $name:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::INFO, { $($field)* }, $($arg)*) + ); + (name: $name:expr, $($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::INFO, { $($k).+ $($field)* }) + ); + (name: $name:expr, ?$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::INFO, { ?$($k).+ $($field)* }) + ); + (name: $name:expr, %$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::INFO, { %$($k).+ $($field)* }) + ); + (name: $name:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, $crate::Level::INFO, {}, $($arg)+) + ); + + // Target. + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)* }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { ?$($k).+ $($field)* }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { %$($k).+ $($field)* }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::INFO, {}, $($arg)+) + ); + + // Parent. (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1563,21 +2029,8 @@ macro_rules! info { $($arg)+ ) ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)* }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { ?$($k).+ $($field)* }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)* }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::INFO, {}, $($arg)+) - ); + + // ... ({ $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1687,7 +2140,42 @@ macro_rules! info { /// ``` #[macro_export] macro_rules! warn { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + // Name / target / parent. + (name: $name:expr, target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) + ); + + // Name / target. + (name: $name:expr, target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*) + ); + (name: $name:expr, target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::WARN, {}, $($arg)+) + ); + + // Target / parent. + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) ); (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( @@ -1702,6 +2190,59 @@ macro_rules! warn { (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) ); + + // Name / parent. + (name: $name:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) + ); + (name: $name:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::WARN, {}, $($arg)+) + ); + + // Name. + (name: $name:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::WARN, { $($field)* }, $($arg)*) + ); + (name: $name:expr, $($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::WARN, { $($k).+ $($field)* }) + ); + (name: $name:expr, ?$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::WARN, { ?$($k).+ $($field)* }) + ); + (name: $name:expr, %$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::WARN, { %$($k).+ $($field)* }) + ); + (name: $name:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, $crate::Level::WARN, {}, $($arg)+) + ); + + // Target. + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)* }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { ?$($k).+ $($field)* }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { %$($k).+ $($field)* }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::WARN, {}, $($arg)+) + ); + + // Parent. (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1768,21 +2309,8 @@ macro_rules! warn { $($arg)+ ) ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)* }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { ?$($k).+ $($field)* }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { %$($k).+ $($field)* }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::WARN, {}, $($arg)+) - ); + + // ... ({ $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1888,7 +2416,42 @@ macro_rules! warn { /// ``` #[macro_export] macro_rules! error { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + // Name / target / parent. + (name: $name:expr, target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) + ); + + // Name / target. + (name: $name:expr, target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*) + ); + (name: $name:expr, target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (name: $name:expr, target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, target: $target, $crate::Level::ERROR, {}, $($arg)+) + ); + + // Target / parent. + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) ); (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( @@ -1903,6 +2466,59 @@ macro_rules! error { (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) ); + + // Name / parent. + (name: $name:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) + ); + (name: $name:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) + ); + + // Name. + (name: $name:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::ERROR, { $($field)* }, $($arg)*) + ); + (name: $name:expr, $($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::ERROR, { $($k).+ $($field)* }) + ); + (name: $name:expr, ?$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::ERROR, { ?$($k).+ $($field)* }) + ); + (name: $name:expr, %$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(name: $name, $crate::Level::ERROR, { %$($k).+ $($field)* }) + ); + (name: $name:expr, $($arg:tt)+ ) => ( + $crate::event!(name: $name, $crate::Level::ERROR, {}, $($arg)+) + ); + + // Target. + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)* }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { ?$($k).+ $($field)* }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { %$($k).+ $($field)* }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, {}, $($arg)+) + ); + + // Parent. (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1969,21 +2585,8 @@ macro_rules! error { $($arg)+ ) ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)* }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { ?$($k).+ $($field)* }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { %$($k).+ $($field)* }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, {}, $($arg)+) - ); + + // ... ({ $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), diff --git a/tracing/tests/macros.rs b/tracing/tests/macros.rs index 6d9a333b68..93204861aa 100644 --- a/tracing/tests/macros.rs +++ b/tracing/tests/macros.rs @@ -409,6 +409,13 @@ fn locals_no_message() { let data = (42, "forty-two"); let private_data = "private"; let error = "a bad error"; + event!( + name: "foo", + target: "app_events", + Level::WARN, + private_data, + ?data, + ); event!( target: "app_events", Level::WARN, @@ -448,6 +455,8 @@ fn trace() { trace!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); trace!({ foo = 2, bar.baz = 78 }, "quux"); trace!({ foo = ?2, bar.baz = %78 }, "quux"); + trace!(name: "foo", foo = 3, bar.baz = 2, quux = false); + trace!(name: "foo", target: "foo_events", foo = 3, bar.baz = 2, quux = false); trace!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); trace!(target: "foo_events", foo = 3, bar.baz = 3,); trace!(target: "foo_events", "foo"); @@ -460,6 +469,12 @@ fn trace() { trace!(?foo); trace!(%foo); trace!(foo); + trace!(name: "foo", ?foo); + trace!(name: "foo", %foo); + trace!(name: "foo", foo); + trace!(name: "foo", ?foo, true, "message"); + trace!(name: "foo", %foo, true, "message"); + trace!(name: "foo", foo, true, "message"); trace!(target: "foo_events", ?foo); trace!(target: "foo_events", %foo); trace!(target: "foo_events", foo); @@ -484,6 +499,8 @@ fn debug() { debug!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); debug!({ foo = 2, bar.baz = 78 }, "quux"); debug!({ foo = ?2, bar.baz = %78 }, "quux"); + debug!(name: "foo", foo = 3, bar.baz = 2, quux = false); + debug!(name: "foo", target: "foo_events", foo = 3, bar.baz = 2, quux = false); debug!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); debug!(target: "foo_events", foo = 3, bar.baz = 3,); debug!(target: "foo_events", "foo"); @@ -496,6 +513,12 @@ fn debug() { debug!(?foo); debug!(%foo); debug!(foo); + debug!(name: "foo", ?foo); + debug!(name: "foo", %foo); + debug!(name: "foo", foo); + debug!(name: "foo", ?foo, true, "message"); + debug!(name: "foo", %foo, true, "message"); + debug!(name: "foo", foo, true, "message"); debug!(target: "foo_events", ?foo); debug!(target: "foo_events", %foo); debug!(target: "foo_events", foo); @@ -520,6 +543,8 @@ fn info() { info!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); info!({ foo = 2, bar.baz = 78 }, "quux"); info!({ foo = ?2, bar.baz = %78 }, "quux"); + info!(name: "foo", foo = 3, bar.baz = 2, quux = false); + info!(name: "foo", target: "foo_events", foo = 3, bar.baz = 2, quux = false); info!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); info!(target: "foo_events", foo = 3, bar.baz = 3,); info!(target: "foo_events", "foo"); @@ -532,6 +557,12 @@ fn info() { info!(?foo); info!(%foo); info!(foo); + info!(name: "foo", ?foo); + info!(name: "foo", %foo); + info!(name: "foo", foo); + info!(name: "foo", ?foo, true, "message"); + info!(name: "foo", %foo, true, "message"); + info!(name: "foo", foo, true, "message"); info!(target: "foo_events", ?foo); info!(target: "foo_events", %foo); info!(target: "foo_events", foo); @@ -556,6 +587,8 @@ fn warn() { warn!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); warn!({ foo = 2, bar.baz = 78 }, "quux"); warn!({ foo = ?2, bar.baz = %78 }, "quux"); + warn!(name: "foo", foo = 3, bar.baz = 2, quux = false); + warn!(name: "foo", target: "foo_events", foo = 3, bar.baz = 2, quux = false); warn!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); warn!(target: "foo_events", foo = 3, bar.baz = 3,); warn!(target: "foo_events", "foo"); @@ -568,6 +601,12 @@ fn warn() { warn!(?foo); warn!(%foo); warn!(foo); + warn!(name: "foo", ?foo); + warn!(name: "foo", %foo); + warn!(name: "foo", foo); + warn!(name: "foo", ?foo, true, "message"); + warn!(name: "foo", %foo, true, "message"); + warn!(name: "foo", foo, true, "message"); warn!(target: "foo_events", ?foo); warn!(target: "foo_events", %foo); warn!(target: "foo_events", foo); @@ -592,6 +631,8 @@ fn error() { error!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); error!({ foo = 2, bar.baz = 78, }, "quux"); error!({ foo = ?2, bar.baz = %78 }, "quux"); + error!(name: "foo", foo = 3, bar.baz = 2, quux = false); + error!(name: "foo", target: "foo_events", foo = 3, bar.baz = 2, quux = false); error!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); error!(target: "foo_events", foo = 3, bar.baz = 3,); error!(target: "foo_events", "foo"); @@ -604,6 +645,12 @@ fn error() { error!(?foo); error!(%foo); error!(foo); + error!(name: "foo", ?foo); + error!(name: "foo", %foo); + error!(name: "foo", foo); + error!(name: "foo", ?foo, true, "message"); + error!(name: "foo", %foo, true, "message"); + error!(name: "foo", foo, true, "message"); error!(target: "foo_events", ?foo); error!(target: "foo_events", %foo); error!(target: "foo_events", foo); @@ -638,6 +685,14 @@ fn event_root() { event!(target: "foo_events", parent: ::core::option::Option::None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); event!(target: "foo_events", parent: ::core::option::Option::None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); event!(target: "foo_events", parent: ::core::option::Option::None, Level::DEBUG, { foo = 2, bar.baz = 78, }, "quux"); + event!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, Level::DEBUG, foo = 3, bar.baz = 2, quux = false); + event!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, Level::DEBUG, foo = 3, bar.baz = 3,); + event!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, Level::DEBUG, "foo"); + event!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, Level::DEBUG, "foo: {}", 3); + event!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); + event!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + event!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + event!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, Level::DEBUG, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] @@ -661,6 +716,14 @@ fn trace_root() { trace!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); trace!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); trace!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 78, }, "quux"); + trace!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, foo = 3, bar.baz = 2, quux = false); + trace!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, foo = 3, bar.baz = 3,); + trace!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, "foo"); + trace!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, "foo: {}", 3); + trace!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 3, bar.baz = 80 }, "quux"); + trace!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + trace!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + trace!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] @@ -684,6 +747,14 @@ fn debug_root() { debug!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); debug!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); debug!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 78, }, "quux"); + debug!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, foo = 3, bar.baz = 2, quux = false); + debug!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, foo = 3, bar.baz = 3,); + debug!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, "foo"); + debug!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, "foo: {}", 3); + debug!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 3, bar.baz = 80 }, "quux"); + debug!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + debug!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + debug!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] @@ -707,6 +778,14 @@ fn info_root() { info!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); info!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); info!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 78, }, "quux"); + info!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, foo = 3, bar.baz = 2, quux = false); + info!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, foo = 3, bar.baz = 3,); + info!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, "foo"); + info!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, "foo: {}", 3); + info!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 3, bar.baz = 80 }, "quux"); + info!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + info!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + info!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] @@ -730,6 +809,14 @@ fn warn_root() { warn!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); warn!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); warn!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 78, }, "quux"); + warn!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, foo = 3, bar.baz = 2, quux = false); + warn!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, foo = 3, bar.baz = 3,); + warn!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, "foo"); + warn!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, "foo: {}", 3); + warn!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 3, bar.baz = 80 }, "quux"); + warn!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + warn!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + warn!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] @@ -753,6 +840,14 @@ fn error_root() { error!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); error!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); error!(target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 78, }, "quux"); + error!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, foo = 3, bar.baz = 2, quux = false); + error!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, foo = 3, bar.baz = 3,); + error!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, "foo"); + error!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, "foo: {}", 3); + error!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 3, bar.baz = 80 }, "quux"); + error!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + error!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + error!(name: "foo", target: "foo_events", parent: ::core::option::Option::None, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] @@ -776,6 +871,14 @@ fn event_with_parent() { event!(target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); event!(target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); event!(target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 78, }, "quux"); + event!(name: "foo", target: "foo_events", parent: &p, Level::DEBUG, foo = 3, bar.baz = 2, quux = false); + event!(name: "foo", target: "foo_events", parent: &p, Level::DEBUG, foo = 3, bar.baz = 3,); + event!(name: "foo", target: "foo_events", parent: &p, Level::DEBUG, "foo"); + event!(name: "foo", target: "foo_events", parent: &p, Level::DEBUG, "foo: {}", 3); + event!(name: "foo", target: "foo_events", parent: &p, Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); + event!(name: "foo", target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + event!(name: "foo", target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + event!(name: "foo", target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] @@ -800,6 +903,14 @@ fn trace_with_parent() { trace!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); trace!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); trace!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); + trace!(name: "foo", target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); + trace!(name: "foo", target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); + trace!(name: "foo", target: "foo_events", parent: &p, "foo"); + trace!(name: "foo", target: "foo_events", parent: &p, "foo: {}", 3); + trace!(name: "foo", target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); + trace!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + trace!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + trace!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] @@ -824,6 +935,14 @@ fn debug_with_parent() { debug!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); debug!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); debug!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); + debug!(name: "foo", target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); + debug!(name: "foo", target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); + debug!(name: "foo", target: "foo_events", parent: &p, "foo"); + debug!(name: "foo", target: "foo_events", parent: &p, "foo: {}", 3); + debug!(name: "foo", target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); + debug!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + debug!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + debug!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] @@ -848,6 +967,14 @@ fn info_with_parent() { info!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); info!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); info!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); + info!(name: "foo", target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); + info!(name: "foo", target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); + info!(name: "foo", target: "foo_events", parent: &p, "foo"); + info!(name: "foo", target: "foo_events", parent: &p, "foo: {}", 3); + info!(name: "foo", target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); + info!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + info!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + info!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] @@ -872,6 +999,14 @@ fn warn_with_parent() { warn!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); warn!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); warn!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); + warn!(name: "foo", target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); + warn!(name: "foo", target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); + warn!(name: "foo", target: "foo_events", parent: &p, "foo"); + warn!(name: "foo", target: "foo_events", parent: &p, "foo: {}", 3); + warn!(name: "foo", target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); + warn!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + warn!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + warn!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] @@ -896,6 +1031,14 @@ fn error_with_parent() { error!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); error!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); error!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); + error!(name: "foo", target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); + error!(name: "foo", target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); + error!(name: "foo", target: "foo_events", parent: &p, "foo"); + error!(name: "foo", target: "foo_events", parent: &p, "foo: {}", 3); + error!(name: "foo", target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); + error!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); + error!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); + error!(name: "foo", target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] From f7e44469fb4c29c19de50d4358090c803985d845 Mon Sep 17 00:00:00 2001 From: Aaron Roney Date: Mon, 4 Sep 2023 23:38:20 -0700 Subject: [PATCH 2/7] Update docs for `event!` `name` option. --- tracing/src/lib.rs | 3 ++- tracing/src/macros.rs | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tracing/src/lib.rs b/tracing/src/lib.rs index de54bffbd2..9b1cb0f1a5 100644 --- a/tracing/src/lib.rs +++ b/tracing/src/lib.rs @@ -225,7 +225,7 @@ //! # use tracing::{span, event, Level}; //! # fn main() { //! span!(target: "app_spans", Level::TRACE, "my span"); -//! event!(target: "app_events", Level::INFO, "something has happened!"); +//! event!(name: "event", target: "app_events", Level::INFO, "something has happened!"); //! # } //! ``` //! ``` @@ -421,6 +421,7 @@ //! // - "message", with the value "the answer to the ultimate question of life, the //! // universe, and everything is 42." //! event!( +//! name: "life", //! Level::DEBUG, //! question.answer = answer, //! question.tricky = true, diff --git a/tracing/src/macros.rs b/tracing/src/macros.rs index 3640af62a4..45ca3f6c2d 100644 --- a/tracing/src/macros.rs +++ b/tracing/src/macros.rs @@ -565,6 +565,7 @@ macro_rules! error_span { /// "App warning: {}", /// error /// ); +/// event!(name: "answer", Level::INFO, the_answer = data.0); /// event!(Level::INFO, the_answer = data.0); /// # } /// ``` @@ -1293,6 +1294,7 @@ macro_rules! enabled { /// if pos.x >= 0.0 { "positive" } else { "negative" }, /// if pos.y >= 0.0 { "positive" } else { "negative" } /// ); +/// trace!(name: "completed", position = ?pos); /// # } /// ``` #[macro_export] @@ -1569,6 +1571,7 @@ macro_rules! trace { /// /// debug!(?pos.x, ?pos.y); /// debug!(target: "app_events", position = ?pos, "New position"); +/// debug!(name: "completed", position = ?pos); /// # } /// ``` #[macro_export] @@ -1856,6 +1859,7 @@ macro_rules! debug { /// conn.port, /// ?conn.speed, /// ); +/// info!(name: "completed", addr); /// # } /// ``` #[macro_export] @@ -2136,6 +2140,7 @@ macro_rules! info { /// warning = warn_description, /// "Received warning for input: {:?}", input, /// ); +/// warn!(name: "invalid"); /// # } /// ``` #[macro_export] @@ -2412,6 +2417,7 @@ macro_rules! warn { /// error!(port, error = %err_info); /// error!(target: "app_events", "App Error: {}", err_info); /// error!({ info = err_info }, "error on port: {}", port); +/// error!(name: "invalid_input", "Invalid input: {}", input); /// # } /// ``` #[macro_export] From b8eeacf144656bdd453265e7dd23e4e0c4cf81d7 Mon Sep 17 00:00:00 2001 From: Aaron Roney Date: Tue, 5 Sep 2023 10:45:02 -0700 Subject: [PATCH 3/7] Fix docs. --- tracing/src/lib.rs | 14 +++++++++++--- tracing/src/macros.rs | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tracing/src/lib.rs b/tracing/src/lib.rs index 9b1cb0f1a5..4f0f69d10b 100644 --- a/tracing/src/lib.rs +++ b/tracing/src/lib.rs @@ -225,7 +225,7 @@ //! # use tracing::{span, event, Level}; //! # fn main() { //! span!(target: "app_spans", Level::TRACE, "my span"); -//! event!(name: "event", target: "app_events", Level::INFO, "something has happened!"); +//! event!(target: "app_events", Level::INFO, "something has happened!"); //! # } //! ``` //! ``` @@ -237,7 +237,16 @@ //! ``` //! //! The span macros also take a string literal after the level, to set the name -//! of the span. +//! of the span (as above). In the case of the event macros, the name of the event can +//! be overrided (the default is `event file:line`) using the `name:` specifier. +//! +//! ``` +//! # use tracing::{span, event, Level}; +//! # fn main() { +//! span!(Level::TRACE, "my span"); +//! event!(name: "spurious_info", Level::INFO, "something has happened!"); +//! # } +//! ``` //! //! ### Recording Fields //! @@ -421,7 +430,6 @@ //! // - "message", with the value "the answer to the ultimate question of life, the //! // universe, and everything is 42." //! event!( -//! name: "life", //! Level::DEBUG, //! question.answer = answer, //! question.tricky = true, diff --git a/tracing/src/macros.rs b/tracing/src/macros.rs index 45ca3f6c2d..082be6dd46 100644 --- a/tracing/src/macros.rs +++ b/tracing/src/macros.rs @@ -1859,7 +1859,7 @@ macro_rules! debug { /// conn.port, /// ?conn.speed, /// ); -/// info!(name: "completed", addr); +/// info!(name: "completed", "completed connection to {:?}", addr); /// # } /// ``` #[macro_export] @@ -2140,7 +2140,7 @@ macro_rules! info { /// warning = warn_description, /// "Received warning for input: {:?}", input, /// ); -/// warn!(name: "invalid"); +/// warn!(name: "invalid", ?input); /// # } /// ``` #[macro_export] @@ -2417,7 +2417,7 @@ macro_rules! warn { /// error!(port, error = %err_info); /// error!(target: "app_events", "App Error: {}", err_info); /// error!({ info = err_info }, "error on port: {}", port); -/// error!(name: "invalid_input", "Invalid input: {}", input); +/// error!(name: "invalid_input", "Invalid input: {}", err_info); /// # } /// ``` #[macro_export] From 14f27f28fb6fe86dff669b9e9e0e2c4f79ee14be Mon Sep 17 00:00:00 2001 From: Aaron Roney Date: Tue, 5 Sep 2023 10:53:59 -0700 Subject: [PATCH 4/7] =?UTF-8?q?Fix=20poor=20grammar.=20=F0=9F=98=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tracing/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracing/src/lib.rs b/tracing/src/lib.rs index 4f0f69d10b..c736a04820 100644 --- a/tracing/src/lib.rs +++ b/tracing/src/lib.rs @@ -238,13 +238,13 @@ //! //! The span macros also take a string literal after the level, to set the name //! of the span (as above). In the case of the event macros, the name of the event can -//! be overrided (the default is `event file:line`) using the `name:` specifier. +//! be overridden (the default is `event file:line`) using the `name:` specifier. //! //! ``` //! # use tracing::{span, event, Level}; //! # fn main() { //! span!(Level::TRACE, "my span"); -//! event!(name: "spurious_info", Level::INFO, "something has happened!"); +//! event!(name: "some_info", Level::INFO, "something has happened!"); //! # } //! ``` //! From 2f7ec4c01c46886e44569063eae2d8cef2459021 Mon Sep 17 00:00:00 2001 From: Aaron Roney Date: Tue, 5 Sep 2023 10:59:03 -0700 Subject: [PATCH 5/7] Update "attributes" paragraph. --- tracing/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracing/src/lib.rs b/tracing/src/lib.rs index c736a04820..b17c49ea09 100644 --- a/tracing/src/lib.rs +++ b/tracing/src/lib.rs @@ -214,7 +214,7 @@ //! ### Configuring Attributes //! //! Both macros require a [`Level`] specifying the verbosity of the span or -//! event. Optionally, the [target] and [parent span] may be overridden. If the +//! event. Optionally, the name, [target] and [parent span] may be overridden. If the //! target and parent span are not overridden, they will default to the //! module path where the macro was invoked and the current span (as determined //! by the collector), respectively. From 1c74e37335731873de9626609436a0aa3d2eb89e Mon Sep 17 00:00:00 2001 From: Aaron Roney Date: Tue, 5 Sep 2023 12:51:24 -0700 Subject: [PATCH 6/7] Fix whitespace. Co-authored-by: Eliza Weisman --- tracing/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracing/src/lib.rs b/tracing/src/lib.rs index b17c49ea09..c7c0fd0371 100644 --- a/tracing/src/lib.rs +++ b/tracing/src/lib.rs @@ -239,7 +239,7 @@ //! The span macros also take a string literal after the level, to set the name //! of the span (as above). In the case of the event macros, the name of the event can //! be overridden (the default is `event file:line`) using the `name:` specifier. -//! +//! //! ``` //! # use tracing::{span, event, Level}; //! # fn main() { From 51d8d9f1504bbf31faaf5969bf26efa1a0adcf97 Mon Sep 17 00:00:00 2001 From: Aaron Roney Date: Tue, 5 Sep 2023 12:51:59 -0700 Subject: [PATCH 7/7] Remove `name` from optional phrase. Co-authored-by: Eliza Weisman --- tracing/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracing/src/lib.rs b/tracing/src/lib.rs index c7c0fd0371..2088c22f7d 100644 --- a/tracing/src/lib.rs +++ b/tracing/src/lib.rs @@ -214,7 +214,7 @@ //! ### Configuring Attributes //! //! Both macros require a [`Level`] specifying the verbosity of the span or -//! event. Optionally, the name, [target] and [parent span] may be overridden. If the +//! event. Optionally, the, [target] and [parent span] may be overridden. If the //! target and parent span are not overridden, they will default to the //! module path where the macro was invoked and the current span (as determined //! by the collector), respectively.