1 #![deny(warnings)] 2 use tracing::Level; 3 4 #[macro_use] 5 extern crate tracing; 6 // Tests that macros work across various invocation syntax. 7 // 8 // These are quite repetitive, and _could_ be generated by a macro. However, 9 // they're compile-time tests, so I want to get line numbers etc out of 10 // failures, and producing them with a macro would muddy the waters a bit. 11 12 #[test] 13 fn span() { 14 span!(target: "foo_events", Level::DEBUG, "foo", bar.baz = ?2, quux = %3, quuux = 4); 15 span!(target: "foo_events", Level::DEBUG, "foo", bar.baz = 2, quux = 3); 16 span!(target: "foo_events", Level::DEBUG, "foo", bar.baz = 2, quux = 4,); 17 span!(target: "foo_events", Level::DEBUG, "foo"); 18 span!(target: "foo_events", Level::DEBUG, "bar",); 19 span!(Level::DEBUG, "foo", bar.baz = 2, quux = 3); 20 span!(Level::DEBUG, "foo", bar.baz = 2, quux = 4,); 21 span!(Level::DEBUG, "foo", bar.baz = 2, quux = 3); 22 span!(Level::DEBUG, "foo", bar.baz = 2, quux = 4,); 23 span!(Level::DEBUG, "foo", bar.baz = ?2); 24 span!(Level::DEBUG, "foo", bar.baz = %2); 25 span!(Level::DEBUG, "foo"); 26 span!(Level::DEBUG, "bar",); 27 } 28 29 #[test] 30 fn trace_span() { 31 trace_span!(target: "foo_events", "foo", bar.baz = ?2, quux = %3, quuux = 4); 32 trace_span!(target: "foo_events", "foo", bar.baz = 2, quux = 3); 33 trace_span!(target: "foo_events", "foo", bar.baz = 2, quux = 4,); 34 trace_span!(target: "foo_events", "foo"); 35 trace_span!(target: "foo_events", "bar",); 36 trace_span!("foo", bar.baz = 2, quux = 3); 37 trace_span!("foo", bar.baz = 2, quux = 4,); 38 trace_span!("foo", bar.baz = ?2); 39 trace_span!("foo", bar.baz = %2); 40 trace_span!("bar"); 41 trace_span!("bar",); 42 } 43 44 #[test] 45 fn debug_span() { 46 debug_span!(target: "foo_events", "foo", bar.baz = ?2, quux = %3, quuux = 4); 47 debug_span!(target: "foo_events", "foo", bar.baz = 2, quux = 3); 48 debug_span!(target: "foo_events", "foo", bar.baz = 2, quux = 4,); 49 debug_span!(target: "foo_events", "foo"); 50 debug_span!(target: "foo_events", "bar",); 51 debug_span!("foo", bar.baz = 2, quux = 3); 52 debug_span!("foo", bar.baz = 2, quux = 4,); 53 debug_span!("foo", bar.baz = ?2); 54 debug_span!("foo", bar.baz = %2); 55 debug_span!("bar"); 56 debug_span!("bar",); 57 } 58 59 #[test] 60 fn info_span() { 61 info_span!(target: "foo_events", "foo", bar.baz = ?2, quux = %3, quuux = 4); 62 info_span!(target: "foo_events", "foo", bar.baz = 2, quux = 3); 63 info_span!(target: "foo_events", "foo", bar.baz = 2, quux = 4,); 64 info_span!(target: "foo_events", "foo"); 65 info_span!(target: "foo_events", "bar",); 66 info_span!("foo", bar.baz = 2, quux = 3); 67 info_span!("foo", bar.baz = 2, quux = 4,); 68 info_span!("foo", bar.baz = ?2); 69 info_span!("foo", bar.baz = %2); 70 info_span!("bar"); 71 info_span!("bar",); 72 } 73 74 #[test] 75 fn warn_span() { 76 warn_span!(target: "foo_events", "foo", bar.baz = ?2, quux = %3, quuux = 4); 77 warn_span!(target: "foo_events", "foo", bar.baz = 2, quux = 3); 78 warn_span!(target: "foo_events", "foo", bar.baz = 2, quux = 4,); 79 warn_span!(target: "foo_events", "foo"); 80 warn_span!(target: "foo_events", "bar",); 81 warn_span!("foo", bar.baz = 2, quux = 3); 82 warn_span!("foo", bar.baz = 2, quux = 4,); 83 warn_span!("foo", bar.baz = ?2); 84 warn_span!("foo", bar.baz = %2); 85 warn_span!("bar"); 86 warn_span!("bar",); 87 } 88 89 #[test] 90 fn error_span() { 91 error_span!(target: "foo_events", "foo", bar.baz = ?2, quux = %3, quuux = 4); 92 error_span!(target: "foo_events", "foo", bar.baz = 2, quux = 3); 93 error_span!(target: "foo_events", "foo", bar.baz = 2, quux = 4,); 94 error_span!(target: "foo_events", "foo"); 95 error_span!(target: "foo_events", "bar",); 96 error_span!("foo", bar.baz = 2, quux = 3); 97 error_span!("foo", bar.baz = 2, quux = 4,); 98 error_span!("foo", bar.baz = ?2); 99 error_span!("foo", bar.baz = %2); 100 error_span!("bar"); 101 error_span!("bar",); 102 } 103 104 #[test] 105 fn span_root() { 106 span!(target: "foo_events", parent: None, Level::TRACE, "foo", bar.baz = 2, quux = 3); 107 span!(target: "foo_events", parent: None, Level::TRACE, "foo", bar.baz = 2, quux = 3); 108 span!(target: "foo_events", parent: None, Level::TRACE, "foo", bar.baz = 2, quux = 4,); 109 span!(target: "foo_events", parent: None, Level::TRACE, "foo"); 110 span!(target: "foo_events", parent: None, Level::TRACE, "bar",); 111 span!(parent: None, Level::DEBUG, "foo", bar.baz = 2, quux = 3); 112 span!(parent: None, Level::DEBUG, "foo", bar.baz = 2, quux = 4,); 113 span!(parent: None, Level::DEBUG, "foo"); 114 span!(parent: None, Level::DEBUG, "bar",); 115 } 116 117 #[test] 118 fn trace_span_root() { 119 trace_span!(target: "foo_events", parent: None, "foo", bar.baz = 2, quux = 3); 120 trace_span!(target: "foo_events", parent: None, "foo", bar.baz = 2, quux = 4,); 121 trace_span!(target: "foo_events", parent: None, "foo"); 122 trace_span!(target: "foo_events", parent: None, "bar",); 123 trace_span!(parent: None, "foo", bar.baz = 2, quux = 3); 124 trace_span!(parent: None, "foo", bar.baz = 2, quux = 4,); 125 trace_span!(parent: None, "foo"); 126 trace_span!(parent: None, "bar",); 127 } 128 129 #[test] 130 fn debug_span_root() { 131 debug_span!(target: "foo_events", parent: None, "foo", bar.baz = 2, quux = 3); 132 debug_span!(target: "foo_events", parent: None, "foo", bar.baz = 2, quux = 4,); 133 debug_span!(target: "foo_events", parent: None, "foo"); 134 debug_span!(target: "foo_events", parent: None, "bar",); 135 debug_span!(parent: None, "foo", bar.baz = 2, quux = 3); 136 debug_span!(parent: None, "foo", bar.baz = 2, quux = 4,); 137 debug_span!(parent: None, "foo"); 138 debug_span!(parent: None, "bar",); 139 } 140 141 #[test] 142 fn info_span_root() { 143 info_span!(target: "foo_events", parent: None, "foo", bar.baz = 2, quux = 3); 144 info_span!(target: "foo_events", parent: None, "foo", bar.baz = 2, quux = 4,); 145 info_span!(target: "foo_events", parent: None, "foo"); 146 info_span!(target: "foo_events", parent: None, "bar",); 147 info_span!(parent: None, "foo", bar.baz = 2, quux = 3); 148 info_span!(parent: None, "foo", bar.baz = 2, quux = 4,); 149 info_span!(parent: None, "foo"); 150 info_span!(parent: None, "bar",); 151 } 152 153 #[test] 154 fn warn_span_root() { 155 warn_span!(target: "foo_events", parent: None, "foo", bar.baz = 2, quux = 3); 156 warn_span!(target: "foo_events", parent: None, "foo", bar.baz = 2, quux = 4,); 157 warn_span!(target: "foo_events", parent: None, "foo"); 158 warn_span!(target: "foo_events", parent: None, "bar",); 159 warn_span!(parent: None, "foo", bar.baz = 2, quux = 3); 160 warn_span!(parent: None, "foo", bar.baz = 2, quux = 4,); 161 warn_span!(parent: None, "foo"); 162 warn_span!(parent: None, "bar",); 163 } 164 165 #[test] 166 fn error_span_root() { 167 error_span!(target: "foo_events", parent: None, "foo", bar.baz = 2, quux = 3); 168 error_span!(target: "foo_events", parent: None, "foo", bar.baz = 2, quux = 4,); 169 error_span!(target: "foo_events", parent: None, "foo"); 170 error_span!(target: "foo_events", parent: None, "bar",); 171 error_span!(parent: None, "foo", bar.baz = 2, quux = 3); 172 error_span!(parent: None, "foo", bar.baz = 2, quux = 4,); 173 error_span!(parent: None, "foo"); 174 error_span!(parent: None, "bar",); 175 } 176 177 #[test] 178 fn span_with_parent() { 179 let p = span!(Level::TRACE, "im_a_parent!"); 180 span!(target: "foo_events", parent: &p, Level::TRACE, "foo", bar.baz = 2, quux = 3); 181 span!(target: "foo_events", parent: &p, Level::TRACE, "foo", bar.baz = 2, quux = 4,); 182 span!(target: "foo_events", parent: &p, Level::TRACE, "foo"); 183 span!(target: "foo_events", parent: &p, Level::TRACE, "bar",); 184 span!(parent: &p, Level::DEBUG, "foo", bar.baz = 2, quux = 3); 185 span!(parent: &p, Level::DEBUG, "foo", bar.baz = 2, quux = 4,); 186 span!(parent: &p, Level::DEBUG, "foo"); 187 span!(parent: &p, Level::DEBUG, "bar",); 188 } 189 190 #[test] 191 fn trace_span_with_parent() { 192 let p = span!(Level::TRACE, "im_a_parent!"); 193 trace_span!(target: "foo_events", parent: &p, "foo", bar.baz = 2, quux = 3); 194 trace_span!(target: "foo_events", parent: &p, "foo", bar.baz = 2, quux = 4,); 195 trace_span!(target: "foo_events", parent: &p, "foo"); 196 trace_span!(target: "foo_events", parent: &p, "bar",); 197 198 trace_span!(parent: &p, "foo", bar.baz = 2, quux = 3); 199 trace_span!(parent: &p, "foo", bar.baz = 2, quux = 4,); 200 201 trace_span!(parent: &p, "foo"); 202 trace_span!(parent: &p, "bar",); 203 } 204 205 #[test] 206 fn debug_span_with_parent() { 207 let p = span!(Level::TRACE, "im_a_parent!"); 208 debug_span!(target: "foo_events", parent: &p, "foo", bar.baz = 2, quux = 3); 209 debug_span!(target: "foo_events", parent: &p, "foo", bar.baz = 2, quux = 4,); 210 debug_span!(target: "foo_events", parent: &p, "foo"); 211 debug_span!(target: "foo_events", parent: &p, "bar",); 212 213 debug_span!(parent: &p, "foo", bar.baz = 2, quux = 3); 214 debug_span!(parent: &p, "foo", bar.baz = 2, quux = 4,); 215 216 debug_span!(parent: &p, "foo"); 217 debug_span!(parent: &p, "bar",); 218 } 219 220 #[test] 221 fn info_span_with_parent() { 222 let p = span!(Level::TRACE, "im_a_parent!"); 223 info_span!(target: "foo_events", parent: &p, "foo", bar.baz = 2, quux = 3); 224 info_span!(target: "foo_events", parent: &p, "foo", bar.baz = 2, quux = 4,); 225 info_span!(target: "foo_events", parent: &p, "foo"); 226 info_span!(target: "foo_events", parent: &p, "bar",); 227 228 info_span!(parent: &p, "foo", bar.baz = 2, quux = 3); 229 info_span!(parent: &p, "foo", bar.baz = 2, quux = 4,); 230 231 info_span!(parent: &p, "foo"); 232 info_span!(parent: &p, "bar",); 233 } 234 235 #[test] 236 fn warn_span_with_parent() { 237 let p = span!(Level::TRACE, "im_a_parent!"); 238 warn_span!(target: "foo_events", parent: &p, "foo", bar.baz = 2, quux = 3); 239 warn_span!(target: "foo_events", parent: &p, "foo", bar.baz = 2, quux = 4,); 240 warn_span!(target: "foo_events", parent: &p, "foo"); 241 warn_span!(target: "foo_events", parent: &p, "bar",); 242 243 warn_span!(parent: &p, "foo", bar.baz = 2, quux = 3); 244 warn_span!(parent: &p, "foo", bar.baz = 2, quux = 4,); 245 246 warn_span!(parent: &p, "foo"); 247 warn_span!(parent: &p, "bar",); 248 } 249 250 #[test] 251 fn error_span_with_parent() { 252 let p = span!(Level::TRACE, "im_a_parent!"); 253 error_span!(target: "foo_events", parent: &p, "foo", bar.baz = 2, quux = 3); 254 error_span!(target: "foo_events", parent: &p, "foo", bar.baz = 2, quux = 4,); 255 error_span!(target: "foo_events", parent: &p, "foo"); 256 error_span!(target: "foo_events", parent: &p, "bar",); 257 258 error_span!(parent: &p, "foo", bar.baz = 2, quux = 3); 259 error_span!(parent: &p, "foo", bar.baz = 2, quux = 4,); 260 261 error_span!(parent: &p, "foo"); 262 error_span!(parent: &p, "bar",); 263 } 264 265 #[test] 266 fn event() { 267 event!(Level::DEBUG, foo = ?3, bar.baz = %2, quux = false); 268 event!(Level::DEBUG, foo = 3, bar.baz = 2, quux = false); 269 event!(Level::DEBUG, foo = 3, bar.baz = 3,); 270 event!(Level::DEBUG, "foo"); 271 event!(Level::DEBUG, "foo: {}", 3); 272 event!(Level::INFO, foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 273 event!( 274 Level::INFO, 275 foo = 3, 276 bar.baz = 2, 277 quux = false, 278 "hello world {:?}", 279 42 280 ); 281 event!(Level::INFO, foo = 3, bar.baz = 3, "hello world {:?}", 42,); 282 event!(Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 283 event!(Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 284 event!(Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 285 event!(Level::DEBUG, { foo = ?2, bar.baz = %78 }, "quux"); 286 event!(target: "foo_events", Level::DEBUG, foo = 3, bar.baz = 2, quux = false); 287 event!(target: "foo_events", Level::DEBUG, foo = 3, bar.baz = 3,); 288 event!(target: "foo_events", Level::DEBUG, "foo"); 289 event!(target: "foo_events", Level::DEBUG, "foo: {}", 3); 290 event!(target: "foo_events", Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 291 event!(target: "foo_events", Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 292 event!(target: "foo_events", Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 293 event!(target: "foo_events", Level::DEBUG, { foo = 2, bar.baz = 78, }, "quux"); 294 let foo = 1; 295 event!(Level::DEBUG, ?foo); 296 event!(Level::DEBUG, %foo); 297 event!(Level::DEBUG, foo); 298 } 299 300 #[test] 301 fn locals_with_message() { 302 let data = (42, "forty-two"); 303 let private_data = "private"; 304 let error = "a bad error"; 305 event!(Level::ERROR, %error, "Received error"); 306 event!( 307 target: "app_events", 308 Level::WARN, 309 private_data, 310 ?data, 311 "App warning: {}", 312 error 313 ); 314 } 315 316 #[test] 317 fn locals_no_message() { 318 let data = (42, "forty-two"); 319 let private_data = "private"; 320 let error = "a bad error"; 321 event!( 322 target: "app_events", 323 Level::WARN, 324 private_data, 325 ?data, 326 ); 327 event!( 328 target: "app_events", 329 Level::WARN, 330 private_data, 331 ?data, 332 error, 333 ); 334 event!( 335 target: "app_events", 336 Level::WARN, 337 private_data, 338 ?data, 339 error 340 ); 341 event!(Level::WARN, private_data, ?data, error,); 342 } 343 344 #[test] 345 fn trace() { 346 trace!(foo = ?3, bar.baz = %2, quux = false); 347 trace!(foo = 3, bar.baz = 2, quux = false); 348 trace!(foo = 3, bar.baz = 3,); 349 trace!("foo"); 350 trace!("foo: {}", 3); 351 trace!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 352 trace!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42); 353 trace!(foo = 3, bar.baz = 3, "hello world {:?}", 42,); 354 trace!({ foo = 3, bar.baz = 80 }, "quux"); 355 trace!({ foo = 2, bar.baz = 79 }, "quux {:?}", true); 356 trace!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 357 trace!({ foo = 2, bar.baz = 78 }, "quux"); 358 trace!({ foo = ?2, bar.baz = %78 }, "quux"); 359 trace!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); 360 trace!(target: "foo_events", foo = 3, bar.baz = 3,); 361 trace!(target: "foo_events", "foo"); 362 trace!(target: "foo_events", "foo: {}", 3); 363 trace!(target: "foo_events", { foo = 3, bar.baz = 80 }, "quux"); 364 trace!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}", true); 365 trace!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 366 trace!(target: "foo_events", { foo = 2, bar.baz = 78, }, "quux"); 367 let foo = 1; 368 trace!(?foo); 369 trace!(%foo); 370 trace!(foo); 371 } 372 373 #[test] 374 fn debug() { 375 debug!(foo = ?3, bar.baz = %2, quux = false); 376 debug!(foo = 3, bar.baz = 2, quux = false); 377 debug!(foo = 3, bar.baz = 3,); 378 debug!("foo"); 379 debug!("foo: {}", 3); 380 debug!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 381 debug!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42); 382 debug!(foo = 3, bar.baz = 3, "hello world {:?}", 42,); 383 debug!({ foo = 3, bar.baz = 80 }, "quux"); 384 debug!({ foo = 2, bar.baz = 79 }, "quux {:?}", true); 385 debug!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 386 debug!({ foo = 2, bar.baz = 78 }, "quux"); 387 debug!({ foo = ?2, bar.baz = %78 }, "quux"); 388 debug!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); 389 debug!(target: "foo_events", foo = 3, bar.baz = 3,); 390 debug!(target: "foo_events", "foo"); 391 debug!(target: "foo_events", "foo: {}", 3); 392 debug!(target: "foo_events", { foo = 3, bar.baz = 80 }, "quux"); 393 debug!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}", true); 394 debug!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 395 debug!(target: "foo_events", { foo = 2, bar.baz = 78, }, "quux"); 396 let foo = 1; 397 debug!(?foo); 398 debug!(%foo); 399 debug!(foo); 400 } 401 402 #[test] 403 fn info() { 404 info!(foo = ?3, bar.baz = %2, quux = false); 405 info!(foo = 3, bar.baz = 2, quux = false); 406 info!(foo = 3, bar.baz = 3,); 407 info!("foo"); 408 info!("foo: {}", 3); 409 info!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 410 info!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42); 411 info!(foo = 3, bar.baz = 3, "hello world {:?}", 42,); 412 info!({ foo = 3, bar.baz = 80 }, "quux"); 413 info!({ foo = 2, bar.baz = 79 }, "quux {:?}", true); 414 info!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 415 info!({ foo = 2, bar.baz = 78 }, "quux"); 416 info!({ foo = ?2, bar.baz = %78 }, "quux"); 417 info!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); 418 info!(target: "foo_events", foo = 3, bar.baz = 3,); 419 info!(target: "foo_events", "foo"); 420 info!(target: "foo_events", "foo: {}", 3); 421 info!(target: "foo_events", { foo = 3, bar.baz = 80 }, "quux"); 422 info!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}", true); 423 info!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 424 info!(target: "foo_events", { foo = 2, bar.baz = 78, }, "quux"); 425 let foo = 1; 426 info!(?foo); 427 info!(%foo); 428 info!(foo); 429 } 430 431 #[test] 432 fn warn() { 433 warn!(foo = ?3, bar.baz = %2, quux = false); 434 warn!(foo = 3, bar.baz = 2, quux = false); 435 warn!(foo = 3, bar.baz = 3,); 436 warn!("foo"); 437 warn!("foo: {}", 3); 438 warn!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 439 warn!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42); 440 warn!(foo = 3, bar.baz = 3, "hello world {:?}", 42,); 441 warn!({ foo = 3, bar.baz = 80 }, "quux"); 442 warn!({ foo = 2, bar.baz = 79 }, "quux {:?}", true); 443 warn!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 444 warn!({ foo = 2, bar.baz = 78 }, "quux"); 445 warn!({ foo = ?2, bar.baz = %78 }, "quux"); 446 warn!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); 447 warn!(target: "foo_events", foo = 3, bar.baz = 3,); 448 warn!(target: "foo_events", "foo"); 449 warn!(target: "foo_events", "foo: {}", 3); 450 warn!(target: "foo_events", { foo = 3, bar.baz = 80 }, "quux"); 451 warn!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}", true); 452 warn!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 453 warn!(target: "foo_events", { foo = 2, bar.baz = 78, }, "quux"); 454 let foo = 1; 455 warn!(?foo); 456 warn!(%foo); 457 warn!(foo); 458 } 459 460 #[test] 461 fn error() { 462 error!(foo = ?3, bar.baz = %2, quux = false); 463 error!(foo = 3, bar.baz = 2, quux = false); 464 error!(foo = 3, bar.baz = 3,); 465 error!("foo"); 466 error!("foo: {}", 3); 467 error!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 468 error!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42); 469 error!(foo = 3, bar.baz = 3, "hello world {:?}", 42,); 470 error!({ foo = 3, bar.baz = 80 }, "quux"); 471 error!({ foo = 2, bar.baz = 79 }, "quux {:?}", true); 472 error!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 473 error!({ foo = 2, bar.baz = 78, }, "quux"); 474 error!({ foo = ?2, bar.baz = %78 }, "quux"); 475 error!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); 476 error!(target: "foo_events", foo = 3, bar.baz = 3,); 477 error!(target: "foo_events", "foo"); 478 error!(target: "foo_events", "foo: {}", 3); 479 error!(target: "foo_events", { foo = 3, bar.baz = 80 }, "quux"); 480 error!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}", true); 481 error!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 482 error!(target: "foo_events", { foo = 2, bar.baz = 78, }, "quux"); 483 let foo = 1; 484 error!(?foo); 485 error!(%foo); 486 error!(foo); 487 } 488 489 #[test] 490 fn event_root() { 491 event!(parent: None, Level::DEBUG, foo = ?3, bar.baz = %2, quux = false); 492 event!( 493 parent: None, 494 Level::DEBUG, 495 foo = 3, 496 bar.baz = 2, 497 quux = false 498 ); 499 event!(parent: None, Level::DEBUG, foo = 3, bar.baz = 3,); 500 event!(parent: None, Level::DEBUG, "foo"); 501 event!(parent: None, Level::DEBUG, "foo: {}", 3); 502 event!(parent: None, Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 503 event!(parent: None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 504 event!(parent: None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 505 event!(parent: None, Level::DEBUG, { foo = ?2, bar.baz = %78 }, "quux"); 506 event!(target: "foo_events", parent: None, Level::DEBUG, foo = 3, bar.baz = 2, quux = false); 507 event!(target: "foo_events", parent: None, Level::DEBUG, foo = 3, bar.baz = 3,); 508 event!(target: "foo_events", parent: None, Level::DEBUG, "foo"); 509 event!(target: "foo_events", parent: None, Level::DEBUG, "foo: {}", 3); 510 event!(target: "foo_events", parent: None, Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 511 event!(target: "foo_events", parent: None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 512 event!(target: "foo_events", parent: None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 513 event!(target: "foo_events", parent: None, Level::DEBUG, { foo = 2, bar.baz = 78, }, "quux"); 514 } 515 516 #[test] 517 fn trace_root() { 518 trace!(parent: None, foo = ?3, bar.baz = %2, quux = false); 519 trace!(parent: None, foo = 3, bar.baz = 2, quux = false); 520 trace!(parent: None, foo = 3, bar.baz = 3,); 521 trace!(parent: None, "foo"); 522 trace!(parent: None, "foo: {}", 3); 523 trace!(parent: None, { foo = 3, bar.baz = 80 }, "quux"); 524 trace!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 525 trace!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 526 trace!(parent: None, { foo = 2, bar.baz = 78 }, "quux"); 527 trace!(parent: None, { foo = ?2, bar.baz = %78 }, "quux"); 528 trace!(target: "foo_events", parent: None, foo = 3, bar.baz = 2, quux = false); 529 trace!(target: "foo_events", parent: None, foo = 3, bar.baz = 3,); 530 trace!(target: "foo_events", parent: None, "foo"); 531 trace!(target: "foo_events", parent: None, "foo: {}", 3); 532 trace!(target: "foo_events", parent: None, { foo = 3, bar.baz = 80 }, "quux"); 533 trace!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 534 trace!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 535 trace!(target: "foo_events", parent: None, { foo = 2, bar.baz = 78, }, "quux"); 536 } 537 538 #[test] 539 fn debug_root() { 540 debug!(parent: None, foo = ?3, bar.baz = %2, quux = false); 541 debug!(parent: None, foo = 3, bar.baz = 2, quux = false); 542 debug!(parent: None, foo = 3, bar.baz = 3,); 543 debug!(parent: None, "foo"); 544 debug!(parent: None, "foo: {}", 3); 545 debug!(parent: None, { foo = 3, bar.baz = 80 }, "quux"); 546 debug!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 547 debug!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 548 debug!(parent: None, { foo = 2, bar.baz = 78 }, "quux"); 549 debug!(parent: None, { foo = ?2, bar.baz = %78 }, "quux"); 550 debug!(target: "foo_events", parent: None, foo = 3, bar.baz = 2, quux = false); 551 debug!(target: "foo_events", parent: None, foo = 3, bar.baz = 3,); 552 debug!(target: "foo_events", parent: None, "foo"); 553 debug!(target: "foo_events", parent: None, "foo: {}", 3); 554 debug!(target: "foo_events", parent: None, { foo = 3, bar.baz = 80 }, "quux"); 555 debug!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 556 debug!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 557 debug!(target: "foo_events", parent: None, { foo = 2, bar.baz = 78, }, "quux"); 558 } 559 560 #[test] 561 fn info_root() { 562 info!(parent: None, foo = ?3, bar.baz = %2, quux = false); 563 info!(parent: None, foo = 3, bar.baz = 2, quux = false); 564 info!(parent: None, foo = 3, bar.baz = 3,); 565 info!(parent: None, "foo"); 566 info!(parent: None, "foo: {}", 3); 567 info!(parent: None, { foo = 3, bar.baz = 80 }, "quux"); 568 info!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 569 info!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 570 info!(parent: None, { foo = 2, bar.baz = 78 }, "quux"); 571 info!(parent: None, { foo = ?2, bar.baz = %78 }, "quux"); 572 info!(target: "foo_events", parent: None, foo = 3, bar.baz = 2, quux = false); 573 info!(target: "foo_events", parent: None, foo = 3, bar.baz = 3,); 574 info!(target: "foo_events", parent: None, "foo"); 575 info!(target: "foo_events", parent: None, "foo: {}", 3); 576 info!(target: "foo_events", parent: None, { foo = 3, bar.baz = 80 }, "quux"); 577 info!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 578 info!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 579 info!(target: "foo_events", parent: None, { foo = 2, bar.baz = 78, }, "quux"); 580 } 581 582 #[test] 583 fn warn_root() { 584 warn!(parent: None, foo = ?3, bar.baz = %2, quux = false); 585 warn!(parent: None, foo = 3, bar.baz = 2, quux = false); 586 warn!(parent: None, foo = 3, bar.baz = 3,); 587 warn!(parent: None, "foo"); 588 warn!(parent: None, "foo: {}", 3); 589 warn!(parent: None, { foo = 3, bar.baz = 80 }, "quux"); 590 warn!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 591 warn!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 592 warn!(parent: None, { foo = 2, bar.baz = 78 }, "quux"); 593 warn!(parent: None, { foo = ?2, bar.baz = %78 }, "quux"); 594 warn!(target: "foo_events", parent: None, foo = 3, bar.baz = 2, quux = false); 595 warn!(target: "foo_events", parent: None, foo = 3, bar.baz = 3,); 596 warn!(target: "foo_events", parent: None, "foo"); 597 warn!(target: "foo_events", parent: None, "foo: {}", 3); 598 warn!(target: "foo_events", parent: None, { foo = 3, bar.baz = 80 }, "quux"); 599 warn!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 600 warn!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 601 warn!(target: "foo_events", parent: None, { foo = 2, bar.baz = 78, }, "quux"); 602 } 603 604 #[test] 605 fn error_root() { 606 error!(parent: None, foo = ?3, bar.baz = %2, quux = false); 607 error!(parent: None, foo = 3, bar.baz = 2, quux = false); 608 error!(parent: None, foo = 3, bar.baz = 3,); 609 error!(parent: None, "foo"); 610 error!(parent: None, "foo: {}", 3); 611 error!(parent: None, { foo = 3, bar.baz = 80 }, "quux"); 612 error!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 613 error!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 614 error!(parent: None, { foo = 2, bar.baz = 78 }, "quux"); 615 error!(parent: None, { foo = ?2, bar.baz = %78 }, "quux"); 616 error!(target: "foo_events", parent: None, foo = 3, bar.baz = 2, quux = false); 617 error!(target: "foo_events", parent: None, foo = 3, bar.baz = 3,); 618 error!(target: "foo_events", parent: None, "foo"); 619 error!(target: "foo_events", parent: None, "foo: {}", 3); 620 error!(target: "foo_events", parent: None, { foo = 3, bar.baz = 80 }, "quux"); 621 error!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 622 error!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 623 error!(target: "foo_events", parent: None, { foo = 2, bar.baz = 78, }, "quux"); 624 } 625 626 #[test] 627 fn event_with_parent() { 628 let p = span!(Level::TRACE, "im_a_parent!"); 629 event!(parent: &p, Level::DEBUG, foo = ?3, bar.baz = %2, quux = false); 630 event!(parent: &p, Level::DEBUG, foo = 3, bar.baz = 2, quux = false); 631 event!(parent: &p, Level::DEBUG, foo = 3, bar.baz = 3,); 632 event!(parent: &p, Level::DEBUG, "foo"); 633 event!(parent: &p, Level::DEBUG, "foo: {}", 3); 634 event!(parent: &p, Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 635 event!(parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 636 event!(parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 637 event!(parent: &p, Level::DEBUG, { foo = ?2, bar.baz = %78 }, "quux"); 638 event!(target: "foo_events", parent: &p, Level::DEBUG, foo = 3, bar.baz = 2, quux = false); 639 event!(target: "foo_events", parent: &p, Level::DEBUG, foo = 3, bar.baz = 3,); 640 event!(target: "foo_events", parent: &p, Level::DEBUG, "foo"); 641 event!(target: "foo_events", parent: &p, Level::DEBUG, "foo: {}", 3); 642 event!(target: "foo_events", parent: &p, Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 643 event!(target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 644 event!(target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 645 event!(target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 78, }, "quux"); 646 } 647 648 #[test] 649 fn trace_with_parent() { 650 let p = span!(Level::TRACE, "im_a_parent!"); 651 trace!(parent: &p, foo = ?3, bar.baz = %2, quux = false); 652 trace!(parent: &p, foo = 3, bar.baz = 2, quux = false); 653 trace!(parent: &p, foo = 3, bar.baz = 3,); 654 trace!(parent: &p, "foo"); 655 trace!(parent: &p, "foo: {}", 3); 656 trace!(parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 657 trace!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 658 trace!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 659 trace!(parent: &p, { foo = 2, bar.baz = 78 }, "quux"); 660 trace!(parent: &p, { foo = ?2, bar.baz = %78 }, "quux"); 661 trace!(target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); 662 trace!(target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); 663 trace!(target: "foo_events", parent: &p, "foo"); 664 trace!(target: "foo_events", parent: &p, "foo: {}", 3); 665 trace!(target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 666 trace!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 667 trace!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 668 trace!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); 669 } 670 671 #[test] 672 fn debug_with_parent() { 673 let p = span!(Level::TRACE, "im_a_parent!"); 674 debug!(parent: &p, foo = ?3, bar.baz = %2, quux = false); 675 debug!(parent: &p, foo = 3, bar.baz = 2, quux = false); 676 debug!(parent: &p, foo = 3, bar.baz = 3,); 677 debug!(parent: &p, "foo"); 678 debug!(parent: &p, "foo: {}", 3); 679 debug!(parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 680 debug!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 681 debug!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 682 debug!(parent: &p, { foo = 2, bar.baz = 78 }, "quux"); 683 debug!(parent: &p, { foo = ?2, bar.baz = %78 }, "quux"); 684 debug!(target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); 685 debug!(target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); 686 debug!(target: "foo_events", parent: &p, "foo"); 687 debug!(target: "foo_events", parent: &p, "foo: {}", 3); 688 debug!(target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 689 debug!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 690 debug!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 691 debug!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); 692 } 693 694 #[test] 695 fn info_with_parent() { 696 let p = span!(Level::TRACE, "im_a_parent!"); 697 info!(parent: &p, foo = ?3, bar.baz = %2, quux = false); 698 info!(parent: &p, foo = 3, bar.baz = 2, quux = false); 699 info!(parent: &p, foo = 3, bar.baz = 3,); 700 info!(parent: &p, "foo"); 701 info!(parent: &p, "foo: {}", 3); 702 info!(parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 703 info!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 704 info!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 705 info!(parent: &p, { foo = 2, bar.baz = 78 }, "quux"); 706 info!(parent: &p, { foo = ?2, bar.baz = %78 }, "quux"); 707 info!(target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); 708 info!(target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); 709 info!(target: "foo_events", parent: &p, "foo"); 710 info!(target: "foo_events", parent: &p, "foo: {}", 3); 711 info!(target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 712 info!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 713 info!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 714 info!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); 715 } 716 717 #[test] 718 fn warn_with_parent() { 719 let p = span!(Level::TRACE, "im_a_parent!"); 720 warn!(parent: &p, foo = ?3, bar.baz = %2, quux = false); 721 warn!(parent: &p, foo = 3, bar.baz = 2, quux = false); 722 warn!(parent: &p, foo = 3, bar.baz = 3,); 723 warn!(parent: &p, "foo"); 724 warn!(parent: &p, "foo: {}", 3); 725 warn!(parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 726 warn!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 727 warn!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 728 warn!(parent: &p, { foo = 2, bar.baz = 78 }, "quux"); 729 warn!(parent: &p, { foo = ?2, bar.baz = %78 }, "quux"); 730 warn!(target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); 731 warn!(target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); 732 warn!(target: "foo_events", parent: &p, "foo"); 733 warn!(target: "foo_events", parent: &p, "foo: {}", 3); 734 warn!(target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 735 warn!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 736 warn!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 737 warn!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); 738 } 739 740 #[test] 741 fn error_with_parent() { 742 let p = span!(Level::TRACE, "im_a_parent!"); 743 error!(parent: &p, foo = ?3, bar.baz = %2, quux = false); 744 error!(parent: &p, foo = 3, bar.baz = 2, quux = false); 745 error!(parent: &p, foo = 3, bar.baz = 3,); 746 error!(parent: &p, "foo"); 747 error!(parent: &p, "foo: {}", 3); 748 error!(parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 749 error!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 750 error!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 751 error!(parent: &p, { foo = 2, bar.baz = 78 }, "quux"); 752 error!(parent: &p, { foo = ?2, bar.baz = %78 }, "quux"); 753 error!(target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); 754 error!(target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); 755 error!(target: "foo_events", parent: &p, "foo"); 756 error!(target: "foo_events", parent: &p, "foo: {}", 3); 757 error!(target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 758 error!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 759 error!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 760 error!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); 761 } 762 763 #[test] 764 fn field_shorthand_only() { 765 #[derive(Debug)] 766 struct Position { 767 x: f32, 768 y: f32, 769 } 770 let pos = Position { 771 x: 3.234, 772 y: -1.223, 773 }; 774 775 trace!(?pos.x, ?pos.y); 776 debug!(?pos.x, ?pos.y); 777 info!(?pos.x, ?pos.y); 778 warn!(?pos.x, ?pos.y); 779 error!(?pos.x, ?pos.y); 780 event!(Level::TRACE, ?pos.x, ?pos.y); 781 } 782 783 #[test] 784 fn callsite_macro_api() { 785 // This test should catch any inadvertent breaking changes 786 // caused by changes to the macro. 787 let _callsite = callsite! { 788 name: "test callsite", 789 kind: tracing::metadata::Kind::EVENT, 790 target: "test target", 791 level: tracing::Level::TRACE, 792 fields: foo, bar, 793 }; 794 let _callsite = callsite! { 795 name: "test callsite", 796 kind: tracing::metadata::Kind::SPAN, 797 level: tracing::Level::TRACE, 798 fields: foo, 799 }; 800 let _callsite = callsite! { 801 name: "test callsite", 802 kind: tracing::metadata::Kind::SPAN, 803 fields: foo, 804 }; 805 } 806