@@ -723,6 +723,10 @@ macro_rules! error_span {
723
723
724
724
/// Constructs a new `Event`.
725
725
///
726
+ /// The event macro is invoked with a `Level` and up to 32 key-value fields.
727
+ /// Optionally, a format string and arguments may follow the fields; this will
728
+ /// be used to construct an implicit field named "message".
729
+ ///
726
730
/// # Examples
727
731
///
728
732
/// ```rust
@@ -733,18 +737,20 @@ macro_rules! error_span {
733
737
/// let private_data = "private";
734
738
/// let error = "a bad error";
735
739
///
736
- /// event!(Level::ERROR, %error, message = "Received error");
737
- /// event!(target: "app_events", Level::WARN, {
738
- /// private_data,
739
- /// ?data,
740
- /// },
741
- /// "App warning: {}", error
740
+ /// event!(Level::ERROR, %error, "Received error");
741
+ /// event!(
742
+ /// target: "app_events",
743
+ /// Level::WARN,
744
+ /// private_data,
745
+ /// ?data,
746
+ /// "App warning: {}",
747
+ /// error
742
748
/// );
743
749
/// event!(Level::INFO, the_answer = data.0);
744
750
/// # }
745
751
/// ```
746
752
///
747
- /// Note that *unlike `$crate:: span!`*, `$crate:: event!` requires a value for all fields. As
753
+ /// Note that *unlike `span!`*, `event!` requires a value for all fields. As
748
754
/// events are recorded immediately when the macro is invoked, there is no
749
755
/// opportunity for fields to be recorded later. A trailing comma on the final
750
756
/// field is valid.
@@ -755,7 +761,7 @@ macro_rules! error_span {
755
761
/// # extern crate tracing;
756
762
/// # use tracing::Level;
757
763
/// # fn main() {
758
- /// event!(Level::Info , foo = 5, bad_field, bar = "hello")
764
+ /// event!(Level::INFO , foo = 5, bad_field, bar = "hello")
759
765
/// #}
760
766
/// ```
761
767
/// Shorthand for `field::debug`:
@@ -839,7 +845,7 @@ macro_rules! event {
839
845
}
840
846
} ) ;
841
847
842
- ( target: $target: expr, parent: $parent: expr, $lvl: expr, { $( $fields: tt) * } , $( $arg: tt) + ) => ( {
848
+ ( target: $target: expr, parent: $parent: expr, $lvl: expr, { $( $fields: tt) * } , $( $arg: tt) + ) => ( {
843
849
$crate:: event!(
844
850
target: $target,
845
851
parent: $parent,
@@ -850,8 +856,8 @@ macro_rules! event {
850
856
( target: $target: expr, parent: $parent: expr, $lvl: expr, $( $k: ident) .+ = $( $fields: tt) * ) => (
851
857
$crate:: event!( target: $target, parent: $parent, $lvl, { $( $k) .+ = $( $fields) * } )
852
858
) ;
853
- ( target: $target: expr, parent: $parent: expr, $lvl: expr, $( $arg: tt) + ) => (
854
- $crate:: event!( target: $target, parent: $parent, $lvl, { } , $( $arg) +)
859
+ ( target: $target: expr, parent: $parent: expr, $lvl: expr, $( $arg: tt) +) => (
860
+ $crate:: event!( target: $target, parent: $parent, $lvl, { $( $arg) + } )
855
861
) ;
856
862
( target: $target: expr, $lvl: expr, { $( $fields: tt) * } ) => ( {
857
863
{
@@ -895,7 +901,7 @@ macro_rules! event {
895
901
$crate:: event!( target: $target, $lvl, { $( $k) .+ = $( $fields) * } )
896
902
) ;
897
903
( target: $target: expr, $lvl: expr, $( $arg: tt) + ) => (
898
- $crate:: event!( target: $target, $lvl, { } , $( $arg) +)
904
+ $crate:: event!( target: $target, $lvl, { $( $arg) + } )
899
905
) ;
900
906
( parent: $parent: expr, $lvl: expr, { $( $fields: tt) * } , $( $arg: tt) + ) => (
901
907
$crate:: event!(
@@ -962,7 +968,7 @@ macro_rules! event {
962
968
)
963
969
) ;
964
970
( parent: $parent: expr, $lvl: expr, $( $arg: tt) + ) => (
965
- $crate:: event!( target: module_path!( ) , parent: $parent, $lvl, { } , $( $arg) +)
971
+ $crate:: event!( target: module_path!( ) , parent: $parent, $lvl, { $( $arg) + } )
966
972
) ;
967
973
( $lvl: expr, { $( $fields: tt) * } , $( $arg: tt) + ) => (
968
974
$crate:: event!(
@@ -1016,7 +1022,7 @@ macro_rules! event {
1016
1022
$crate:: event!( $lvl, $( $k) .+, )
1017
1023
) ;
1018
1024
( $lvl: expr, $( $arg: tt) + ) => (
1019
- $crate:: event!( target: module_path!( ) , $lvl, { } , $( $arg) +)
1025
+ $crate:: event!( target: module_path!( ) , $lvl, { $( $arg) + } )
1020
1026
) ;
1021
1027
}
1022
1028
@@ -1043,11 +1049,13 @@ macro_rules! event {
1043
1049
/// let origin_dist = pos.dist(Position::ORIGIN);
1044
1050
///
1045
1051
/// trace!(position = ?pos, ?origin_dist);
1046
- /// trace!(target: "app_events",
1047
- /// { position = ?pos },
1048
- /// "x is {} and y is {}",
1049
- /// if pos.x >= 0.0 { "positive" } else { "negative" },
1050
- /// if pos.y >= 0.0 { "positive" } else { "negative" });
1052
+ /// trace!(
1053
+ /// target: "app_events",
1054
+ /// position = ?pos,
1055
+ /// "x is {} and y is {}",
1056
+ /// if pos.x >= 0.0 { "positive" } else { "negative" },
1057
+ /// if pos.y >= 0.0 { "positive" } else { "negative" }
1058
+ /// );
1051
1059
/// # }
1052
1060
/// ```
1053
1061
#[ macro_export]
@@ -1231,7 +1239,7 @@ macro_rules! trace {
1231
1239
/// let pos = Position { x: 3.234, y: -1.223 };
1232
1240
///
1233
1241
/// debug!(?pos.x, ?pos.y);
1234
- /// debug!(target: "app_events", { position = ?pos } , "New position");
1242
+ /// debug!(target: "app_events", position = ?pos, "New position");
1235
1243
/// # }
1236
1244
/// ```
1237
1245
#[ macro_export]
@@ -1434,7 +1442,7 @@ macro_rules! debug {
1434
1442
/// let addr = Ipv4Addr::new(127, 0, 0, 1);
1435
1443
/// let conn = Connection { port: 40, speed: 3.20 };
1436
1444
///
1437
- /// info!({ conn.port } , "connected to {:?}", addr);
1445
+ /// info!(conn.port, "connected to {:?}", addr);
1438
1446
/// info!(
1439
1447
/// target: "connection_events",
1440
1448
/// ip = ?addr,
@@ -1640,7 +1648,7 @@ macro_rules! info {
1640
1648
/// warn!(?input, warning = warn_description);
1641
1649
/// warn!(
1642
1650
/// target: "input_events",
1643
- /// { warning = warn_description } ,
1651
+ /// warning = warn_description,
1644
1652
/// "Received warning for input: {:?}", input,
1645
1653
/// );
1646
1654
/// # }
@@ -2123,7 +2131,7 @@ macro_rules! is_enabled {
2123
2131
macro_rules! valueset {
2124
2132
2125
2133
// === base case ===
2126
- ( @ { $( $ val: expr) ,* } , $next: expr, $( , ) * ) => {
2134
+ ( @ { $( , ) * $ ( $ val: expr) ,* $ ( , ) * } , $next: expr $( , ) * ) => {
2127
2135
& [ $( $val) ,* ]
2128
2136
} ;
2129
2137
@@ -2176,6 +2184,42 @@ macro_rules! valueset {
2176
2184
$( $rest) *
2177
2185
)
2178
2186
} ;
2187
+ ( @ { $( $out: expr) ,+ } , $next: expr, $( $k: ident) .+ = ?$val: expr) => {
2188
+ $crate:: valueset!(
2189
+ @ { $( $out) ,+, ( & $next, Some ( & debug( & $val) as & Value ) ) } ,
2190
+ $next,
2191
+ )
2192
+ } ;
2193
+ ( @ { $( $out: expr) ,+ } , $next: expr, $( $k: ident) .+ = %$val: expr) => {
2194
+ $crate:: valueset!(
2195
+ @ { $( $out) ,+, ( & $next, Some ( & display( & $val) as & Value ) ) } ,
2196
+ $next,
2197
+ )
2198
+ } ;
2199
+ ( @ { $( $out: expr) ,+ } , $next: expr, $( $k: ident) .+ = $val: expr) => {
2200
+ $crate:: valueset!(
2201
+ @ { $( $out) ,+, ( & $next, Some ( & $val as & Value ) ) } ,
2202
+ $next,
2203
+ )
2204
+ } ;
2205
+ ( @ { $( $out: expr) ,+ } , $next: expr, $( $k: ident) .+) => {
2206
+ $crate:: valueset!(
2207
+ @ { $( $out) ,+, ( & $next, Some ( & $( $k) .+ as & Value ) ) } ,
2208
+ $next,
2209
+ )
2210
+ } ;
2211
+ ( @ { $( $out: expr) ,+ } , $next: expr, ?$( $k: ident) .+) => {
2212
+ $crate:: valueset!(
2213
+ @ { $( $out) ,+, ( & $next, Some ( & debug( & $( $k) .+) as & Value ) ) } ,
2214
+ $next,
2215
+ )
2216
+ } ;
2217
+ ( @ { $( $out: expr) ,+ } , $next: expr, %$( $k: ident) .+) => {
2218
+ $crate:: valueset!(
2219
+ @ { $( $out) ,+, ( & $next, Some ( & display( & $( $k) .+) as & Value ) ) } ,
2220
+ $next,
2221
+ )
2222
+ } ;
2179
2223
2180
2224
// == recursive case (more tts), empty out set ===
2181
2225
@@ -2202,6 +2246,30 @@ macro_rules! valueset {
2202
2246
( @ { } , $next: expr, %$( $k: ident) .+, $( $rest: tt) * ) => {
2203
2247
$crate:: valueset!( @ { ( & $next, Some ( & display( & $( $k) .+) as & Value ) ) } , $next, $( $rest) * )
2204
2248
} ;
2249
+ // no trailing comma
2250
+ ( @ { } , $next: expr, $( $k: ident) .+ = ?$val: expr) => {
2251
+ $crate:: valueset!( @ { ( & $next, Some ( & debug( & $val) as & Value ) ) } , $next )
2252
+ } ;
2253
+ ( @ { } , $next: expr, $( $k: ident) .+ = %$val: expr) => {
2254
+ $crate:: valueset!( @ { ( & $next, Some ( & display( & $val) as & Value ) ) } , $next)
2255
+ } ;
2256
+ ( @ { } , $next: expr, $( $k: ident) .+ = $val: expr) => {
2257
+ $crate:: valueset!( @ { ( & $next, Some ( & $val as & Value ) ) } , $next)
2258
+ } ;
2259
+ ( @ { } , $next: expr, $( $k: ident) .+) => {
2260
+ $crate:: valueset!( @ { ( & $next, Some ( & $( $k) .+ as & Value ) ) } , $next)
2261
+ } ;
2262
+ ( @ { } , $next: expr, ?$( $k: ident) .+) => {
2263
+ $crate:: valueset!( @ { ( & $next, Some ( & debug( & $( $k) .+) as & Value ) ) } , $next)
2264
+ } ;
2265
+ ( @ { } , $next: expr, %$( $k: ident) .+) => {
2266
+ $crate:: valueset!( @ { ( & $next, Some ( & display( & $( $k) .+) as & Value ) ) } , $next)
2267
+ } ;
2268
+
2269
+ // Remainder is unparseable, but exists --- must be format args!
2270
+ ( @ { $( $out: expr) ,* } , $next: expr, $( $rest: tt) +) => {
2271
+ $crate:: valueset!( @ { $( $out) ,* , ( & $next, Some ( & format_args!( $( $rest) +) as & Value ) ) } , $next, )
2272
+ } ;
2205
2273
2206
2274
// === entry ===
2207
2275
( $fields: expr, $( $kvs: tt) +) => {
@@ -2212,7 +2280,7 @@ macro_rules! valueset {
2212
2280
$fields. value_set( $crate:: valueset!(
2213
2281
@ { } ,
2214
2282
iter. next( ) . expect( "FieldSet corrupted (this is a bug)" ) ,
2215
- $( $kvs) +,
2283
+ $( $kvs) +
2216
2284
) )
2217
2285
}
2218
2286
} ;
@@ -2227,7 +2295,7 @@ macro_rules! valueset {
2227
2295
#[ macro_export]
2228
2296
macro_rules! fieldset {
2229
2297
// == base case ==
2230
- ( @ { $( $out: expr) ,* $( , ) * } $( , ) * ) => {
2298
+ ( @ { $( , ) * $ ( $out: expr) ,* $( , ) * } $( , ) * ) => {
2231
2299
& [ $( $out) ,* ]
2232
2300
} ;
2233
2301
@@ -2282,6 +2350,11 @@ macro_rules! fieldset {
2282
2350
$crate:: fieldset!( @ { $( $out) ,+, $crate:: __tracing_stringify!( $( $k) .+) } $( $rest) * )
2283
2351
} ;
2284
2352
2353
+ // Remainder is unparseable, but exists --- must be format args!
2354
+ ( @ { $( $out: expr) ,* } $( $rest: tt) +) => {
2355
+ $crate:: fieldset!( @ { $( $out) ,* , "message" } )
2356
+ } ;
2357
+
2285
2358
// == entry ==
2286
2359
( $( $args: tt) * ) => {
2287
2360
$crate:: fieldset!( @ { } $( $args) * , )
0 commit comments