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 span_with_non_rust_symbol() { 267 span!(Level::TRACE, "non-rust", "guid:x-request-id" = ?"abcdef", "more {}", 42); 268 span!(Level::TRACE, "non-rust", "guid:x-request-id" = %"abcdef", "more {}", 51); 269 span!( 270 Level::TRACE, 271 "non-rust", 272 "guid:x-request-id" = "abcdef", 273 "more {}", 274 60 275 ); 276 span!(Level::TRACE, "non-rust", "guid:x-request-id" = ?"abcdef"); 277 span!(Level::TRACE, "non-rust", "guid:x-request-id" = %"abcdef"); 278 span!(Level::TRACE, "non-rust", "guid:x-request-id" = "abcdef"); 279 } 280 281 #[test] 282 fn event() { 283 event!(Level::DEBUG, foo = ?3, bar.baz = %2, quux = false); 284 event!(Level::DEBUG, foo = 3, bar.baz = 2, quux = false); 285 event!(Level::DEBUG, foo = 3, bar.baz = 3,); 286 event!(Level::DEBUG, "foo"); 287 event!(Level::DEBUG, "foo: {}", 3); 288 event!(Level::INFO, foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 289 event!( 290 Level::INFO, 291 foo = 3, 292 bar.baz = 2, 293 quux = false, 294 "hello world {:?}", 295 42 296 ); 297 event!(Level::INFO, foo = 3, bar.baz = 3, "hello world {:?}", 42,); 298 event!(Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 299 event!(Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 300 event!(Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 301 event!(Level::DEBUG, { foo = ?2, bar.baz = %78 }, "quux"); 302 event!(target: "foo_events", Level::DEBUG, foo = 3, bar.baz = 2, quux = false); 303 event!(target: "foo_events", Level::DEBUG, foo = 3, bar.baz = 3,); 304 event!(target: "foo_events", Level::DEBUG, "foo"); 305 event!(target: "foo_events", Level::DEBUG, "foo: {}", 3); 306 event!(target: "foo_events", Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 307 event!(target: "foo_events", Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 308 event!(target: "foo_events", Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 309 event!(target: "foo_events", Level::DEBUG, { foo = 2, bar.baz = 78, }, "quux"); 310 let foo = 1; 311 event!(Level::DEBUG, ?foo); 312 event!(Level::DEBUG, %foo); 313 event!(Level::DEBUG, foo); 314 } 315 316 #[test] 317 fn locals_with_message() { 318 let data = (42, "forty-two"); 319 let private_data = "private"; 320 let error = "a bad error"; 321 event!(Level::ERROR, %error, "Received error"); 322 event!( 323 target: "app_events", 324 Level::WARN, 325 private_data, 326 ?data, 327 "App warning: {}", 328 error 329 ); 330 } 331 332 #[test] 333 fn locals_no_message() { 334 let data = (42, "forty-two"); 335 let private_data = "private"; 336 let error = "a bad error"; 337 event!( 338 target: "app_events", 339 Level::WARN, 340 private_data, 341 ?data, 342 ); 343 event!( 344 target: "app_events", 345 Level::WARN, 346 private_data, 347 ?data, 348 error, 349 ); 350 event!( 351 target: "app_events", 352 Level::WARN, 353 private_data, 354 ?data, 355 error 356 ); 357 event!(Level::WARN, private_data, ?data, error,); 358 } 359 360 #[test] 361 fn trace() { 362 trace!(foo = ?3, bar.baz = %2, quux = false); 363 trace!(foo = 3, bar.baz = 2, quux = false); 364 trace!(foo = 3, bar.baz = 3,); 365 trace!("foo"); 366 trace!("foo: {}", 3); 367 trace!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 368 trace!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42); 369 trace!(foo = 3, bar.baz = 3, "hello world {:?}", 42,); 370 trace!({ foo = 3, bar.baz = 80 }, "quux"); 371 trace!({ foo = 2, bar.baz = 79 }, "quux {:?}", true); 372 trace!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 373 trace!({ foo = 2, bar.baz = 78 }, "quux"); 374 trace!({ foo = ?2, bar.baz = %78 }, "quux"); 375 trace!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); 376 trace!(target: "foo_events", foo = 3, bar.baz = 3,); 377 trace!(target: "foo_events", "foo"); 378 trace!(target: "foo_events", "foo: {}", 3); 379 trace!(target: "foo_events", { foo = 3, bar.baz = 80 }, "quux"); 380 trace!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}", true); 381 trace!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 382 trace!(target: "foo_events", { foo = 2, bar.baz = 78, }, "quux"); 383 let foo = 1; 384 trace!(?foo); 385 trace!(%foo); 386 trace!(foo); 387 } 388 389 #[test] 390 fn debug() { 391 debug!(foo = ?3, bar.baz = %2, quux = false); 392 debug!(foo = 3, bar.baz = 2, quux = false); 393 debug!(foo = 3, bar.baz = 3,); 394 debug!("foo"); 395 debug!("foo: {}", 3); 396 debug!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 397 debug!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42); 398 debug!(foo = 3, bar.baz = 3, "hello world {:?}", 42,); 399 debug!({ foo = 3, bar.baz = 80 }, "quux"); 400 debug!({ foo = 2, bar.baz = 79 }, "quux {:?}", true); 401 debug!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 402 debug!({ foo = 2, bar.baz = 78 }, "quux"); 403 debug!({ foo = ?2, bar.baz = %78 }, "quux"); 404 debug!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); 405 debug!(target: "foo_events", foo = 3, bar.baz = 3,); 406 debug!(target: "foo_events", "foo"); 407 debug!(target: "foo_events", "foo: {}", 3); 408 debug!(target: "foo_events", { foo = 3, bar.baz = 80 }, "quux"); 409 debug!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}", true); 410 debug!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 411 debug!(target: "foo_events", { foo = 2, bar.baz = 78, }, "quux"); 412 let foo = 1; 413 debug!(?foo); 414 debug!(%foo); 415 debug!(foo); 416 } 417 418 #[test] 419 fn info() { 420 info!(foo = ?3, bar.baz = %2, quux = false); 421 info!(foo = 3, bar.baz = 2, quux = false); 422 info!(foo = 3, bar.baz = 3,); 423 info!("foo"); 424 info!("foo: {}", 3); 425 info!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 426 info!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42); 427 info!(foo = 3, bar.baz = 3, "hello world {:?}", 42,); 428 info!({ foo = 3, bar.baz = 80 }, "quux"); 429 info!({ foo = 2, bar.baz = 79 }, "quux {:?}", true); 430 info!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 431 info!({ foo = 2, bar.baz = 78 }, "quux"); 432 info!({ foo = ?2, bar.baz = %78 }, "quux"); 433 info!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); 434 info!(target: "foo_events", foo = 3, bar.baz = 3,); 435 info!(target: "foo_events", "foo"); 436 info!(target: "foo_events", "foo: {}", 3); 437 info!(target: "foo_events", { foo = 3, bar.baz = 80 }, "quux"); 438 info!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}", true); 439 info!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 440 info!(target: "foo_events", { foo = 2, bar.baz = 78, }, "quux"); 441 let foo = 1; 442 info!(?foo); 443 info!(%foo); 444 info!(foo); 445 } 446 447 #[test] 448 fn warn() { 449 warn!(foo = ?3, bar.baz = %2, quux = false); 450 warn!(foo = 3, bar.baz = 2, quux = false); 451 warn!(foo = 3, bar.baz = 3,); 452 warn!("foo"); 453 warn!("foo: {}", 3); 454 warn!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 455 warn!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42); 456 warn!(foo = 3, bar.baz = 3, "hello world {:?}", 42,); 457 warn!({ foo = 3, bar.baz = 80 }, "quux"); 458 warn!({ foo = 2, bar.baz = 79 }, "quux {:?}", true); 459 warn!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 460 warn!({ foo = 2, bar.baz = 78 }, "quux"); 461 warn!({ foo = ?2, bar.baz = %78 }, "quux"); 462 warn!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); 463 warn!(target: "foo_events", foo = 3, bar.baz = 3,); 464 warn!(target: "foo_events", "foo"); 465 warn!(target: "foo_events", "foo: {}", 3); 466 warn!(target: "foo_events", { foo = 3, bar.baz = 80 }, "quux"); 467 warn!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}", true); 468 warn!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 469 warn!(target: "foo_events", { foo = 2, bar.baz = 78, }, "quux"); 470 let foo = 1; 471 warn!(?foo); 472 warn!(%foo); 473 warn!(foo); 474 } 475 476 #[test] 477 fn error() { 478 error!(foo = ?3, bar.baz = %2, quux = false); 479 error!(foo = 3, bar.baz = 2, quux = false); 480 error!(foo = 3, bar.baz = 3,); 481 error!("foo"); 482 error!("foo: {}", 3); 483 error!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42); 484 error!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42); 485 error!(foo = 3, bar.baz = 3, "hello world {:?}", 42,); 486 error!({ foo = 3, bar.baz = 80 }, "quux"); 487 error!({ foo = 2, bar.baz = 79 }, "quux {:?}", true); 488 error!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 489 error!({ foo = 2, bar.baz = 78, }, "quux"); 490 error!({ foo = ?2, bar.baz = %78 }, "quux"); 491 error!(target: "foo_events", foo = 3, bar.baz = 2, quux = false); 492 error!(target: "foo_events", foo = 3, bar.baz = 3,); 493 error!(target: "foo_events", "foo"); 494 error!(target: "foo_events", "foo: {}", 3); 495 error!(target: "foo_events", { foo = 3, bar.baz = 80 }, "quux"); 496 error!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}", true); 497 error!(target: "foo_events", { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 498 error!(target: "foo_events", { foo = 2, bar.baz = 78, }, "quux"); 499 let foo = 1; 500 error!(?foo); 501 error!(%foo); 502 error!(foo); 503 } 504 505 #[test] 506 fn event_root() { 507 event!(parent: None, Level::DEBUG, foo = ?3, bar.baz = %2, quux = false); 508 event!( 509 parent: None, 510 Level::DEBUG, 511 foo = 3, 512 bar.baz = 2, 513 quux = false 514 ); 515 event!(parent: None, Level::DEBUG, foo = 3, bar.baz = 3,); 516 event!(parent: None, Level::DEBUG, "foo"); 517 event!(parent: None, Level::DEBUG, "foo: {}", 3); 518 event!(parent: None, Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 519 event!(parent: None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 520 event!(parent: None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 521 event!(parent: None, Level::DEBUG, { foo = ?2, bar.baz = %78 }, "quux"); 522 event!(target: "foo_events", parent: None, Level::DEBUG, foo = 3, bar.baz = 2, quux = false); 523 event!(target: "foo_events", parent: None, Level::DEBUG, foo = 3, bar.baz = 3,); 524 event!(target: "foo_events", parent: None, Level::DEBUG, "foo"); 525 event!(target: "foo_events", parent: None, Level::DEBUG, "foo: {}", 3); 526 event!(target: "foo_events", parent: None, Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 527 event!(target: "foo_events", parent: None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 528 event!(target: "foo_events", parent: None, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 529 event!(target: "foo_events", parent: None, Level::DEBUG, { foo = 2, bar.baz = 78, }, "quux"); 530 } 531 532 #[test] 533 fn trace_root() { 534 trace!(parent: None, foo = ?3, bar.baz = %2, quux = false); 535 trace!(parent: None, foo = 3, bar.baz = 2, quux = false); 536 trace!(parent: None, foo = 3, bar.baz = 3,); 537 trace!(parent: None, "foo"); 538 trace!(parent: None, "foo: {}", 3); 539 trace!(parent: None, { foo = 3, bar.baz = 80 }, "quux"); 540 trace!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 541 trace!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 542 trace!(parent: None, { foo = 2, bar.baz = 78 }, "quux"); 543 trace!(parent: None, { foo = ?2, bar.baz = %78 }, "quux"); 544 trace!(target: "foo_events", parent: None, foo = 3, bar.baz = 2, quux = false); 545 trace!(target: "foo_events", parent: None, foo = 3, bar.baz = 3,); 546 trace!(target: "foo_events", parent: None, "foo"); 547 trace!(target: "foo_events", parent: None, "foo: {}", 3); 548 trace!(target: "foo_events", parent: None, { foo = 3, bar.baz = 80 }, "quux"); 549 trace!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 550 trace!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 551 trace!(target: "foo_events", parent: None, { foo = 2, bar.baz = 78, }, "quux"); 552 } 553 554 #[test] 555 fn debug_root() { 556 debug!(parent: None, foo = ?3, bar.baz = %2, quux = false); 557 debug!(parent: None, foo = 3, bar.baz = 2, quux = false); 558 debug!(parent: None, foo = 3, bar.baz = 3,); 559 debug!(parent: None, "foo"); 560 debug!(parent: None, "foo: {}", 3); 561 debug!(parent: None, { foo = 3, bar.baz = 80 }, "quux"); 562 debug!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 563 debug!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 564 debug!(parent: None, { foo = 2, bar.baz = 78 }, "quux"); 565 debug!(parent: None, { foo = ?2, bar.baz = %78 }, "quux"); 566 debug!(target: "foo_events", parent: None, foo = 3, bar.baz = 2, quux = false); 567 debug!(target: "foo_events", parent: None, foo = 3, bar.baz = 3,); 568 debug!(target: "foo_events", parent: None, "foo"); 569 debug!(target: "foo_events", parent: None, "foo: {}", 3); 570 debug!(target: "foo_events", parent: None, { foo = 3, bar.baz = 80 }, "quux"); 571 debug!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 572 debug!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 573 debug!(target: "foo_events", parent: None, { foo = 2, bar.baz = 78, }, "quux"); 574 } 575 576 #[test] 577 fn info_root() { 578 info!(parent: None, foo = ?3, bar.baz = %2, quux = false); 579 info!(parent: None, foo = 3, bar.baz = 2, quux = false); 580 info!(parent: None, foo = 3, bar.baz = 3,); 581 info!(parent: None, "foo"); 582 info!(parent: None, "foo: {}", 3); 583 info!(parent: None, { foo = 3, bar.baz = 80 }, "quux"); 584 info!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 585 info!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 586 info!(parent: None, { foo = 2, bar.baz = 78 }, "quux"); 587 info!(parent: None, { foo = ?2, bar.baz = %78 }, "quux"); 588 info!(target: "foo_events", parent: None, foo = 3, bar.baz = 2, quux = false); 589 info!(target: "foo_events", parent: None, foo = 3, bar.baz = 3,); 590 info!(target: "foo_events", parent: None, "foo"); 591 info!(target: "foo_events", parent: None, "foo: {}", 3); 592 info!(target: "foo_events", parent: None, { foo = 3, bar.baz = 80 }, "quux"); 593 info!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 594 info!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 595 info!(target: "foo_events", parent: None, { foo = 2, bar.baz = 78, }, "quux"); 596 } 597 598 #[test] 599 fn warn_root() { 600 warn!(parent: None, foo = ?3, bar.baz = %2, quux = false); 601 warn!(parent: None, foo = 3, bar.baz = 2, quux = false); 602 warn!(parent: None, foo = 3, bar.baz = 3,); 603 warn!(parent: None, "foo"); 604 warn!(parent: None, "foo: {}", 3); 605 warn!(parent: None, { foo = 3, bar.baz = 80 }, "quux"); 606 warn!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 607 warn!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 608 warn!(parent: None, { foo = 2, bar.baz = 78 }, "quux"); 609 warn!(parent: None, { foo = ?2, bar.baz = %78 }, "quux"); 610 warn!(target: "foo_events", parent: None, foo = 3, bar.baz = 2, quux = false); 611 warn!(target: "foo_events", parent: None, foo = 3, bar.baz = 3,); 612 warn!(target: "foo_events", parent: None, "foo"); 613 warn!(target: "foo_events", parent: None, "foo: {}", 3); 614 warn!(target: "foo_events", parent: None, { foo = 3, bar.baz = 80 }, "quux"); 615 warn!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 616 warn!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 617 warn!(target: "foo_events", parent: None, { foo = 2, bar.baz = 78, }, "quux"); 618 } 619 620 #[test] 621 fn error_root() { 622 error!(parent: None, foo = ?3, bar.baz = %2, quux = false); 623 error!(parent: None, foo = 3, bar.baz = 2, quux = false); 624 error!(parent: None, foo = 3, bar.baz = 3,); 625 error!(parent: None, "foo"); 626 error!(parent: None, "foo: {}", 3); 627 error!(parent: None, { foo = 3, bar.baz = 80 }, "quux"); 628 error!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 629 error!(parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 630 error!(parent: None, { foo = 2, bar.baz = 78 }, "quux"); 631 error!(parent: None, { foo = ?2, bar.baz = %78 }, "quux"); 632 error!(target: "foo_events", parent: None, foo = 3, bar.baz = 2, quux = false); 633 error!(target: "foo_events", parent: None, foo = 3, bar.baz = 3,); 634 error!(target: "foo_events", parent: None, "foo"); 635 error!(target: "foo_events", parent: None, "foo: {}", 3); 636 error!(target: "foo_events", parent: None, { foo = 3, bar.baz = 80 }, "quux"); 637 error!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 638 error!(target: "foo_events", parent: None, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 639 error!(target: "foo_events", parent: None, { foo = 2, bar.baz = 78, }, "quux"); 640 } 641 642 #[test] 643 fn event_with_parent() { 644 let p = span!(Level::TRACE, "im_a_parent!"); 645 event!(parent: &p, Level::DEBUG, foo = ?3, bar.baz = %2, quux = false); 646 event!(parent: &p, Level::DEBUG, foo = 3, bar.baz = 2, quux = false); 647 event!(parent: &p, Level::DEBUG, foo = 3, bar.baz = 3,); 648 event!(parent: &p, Level::DEBUG, "foo"); 649 event!(parent: &p, Level::DEBUG, "foo: {}", 3); 650 event!(parent: &p, Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 651 event!(parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 652 event!(parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 653 event!(parent: &p, Level::DEBUG, { foo = ?2, bar.baz = %78 }, "quux"); 654 event!(target: "foo_events", parent: &p, Level::DEBUG, foo = 3, bar.baz = 2, quux = false); 655 event!(target: "foo_events", parent: &p, Level::DEBUG, foo = 3, bar.baz = 3,); 656 event!(target: "foo_events", parent: &p, Level::DEBUG, "foo"); 657 event!(target: "foo_events", parent: &p, Level::DEBUG, "foo: {}", 3); 658 event!(target: "foo_events", parent: &p, Level::DEBUG, { foo = 3, bar.baz = 80 }, "quux"); 659 event!(target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 660 event!(target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 661 event!(target: "foo_events", parent: &p, Level::DEBUG, { foo = 2, bar.baz = 78, }, "quux"); 662 } 663 664 #[test] 665 fn trace_with_parent() { 666 let p = span!(Level::TRACE, "im_a_parent!"); 667 trace!(parent: &p, foo = ?3, bar.baz = %2, quux = false); 668 trace!(parent: &p, foo = 3, bar.baz = 2, quux = false); 669 trace!(parent: &p, foo = 3, bar.baz = 3,); 670 trace!(parent: &p, "foo"); 671 trace!(parent: &p, "foo: {}", 3); 672 trace!(parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 673 trace!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 674 trace!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 675 trace!(parent: &p, { foo = 2, bar.baz = 78 }, "quux"); 676 trace!(parent: &p, { foo = ?2, bar.baz = %78 }, "quux"); 677 trace!(target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); 678 trace!(target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); 679 trace!(target: "foo_events", parent: &p, "foo"); 680 trace!(target: "foo_events", parent: &p, "foo: {}", 3); 681 trace!(target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 682 trace!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 683 trace!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 684 trace!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); 685 } 686 687 #[test] 688 fn debug_with_parent() { 689 let p = span!(Level::TRACE, "im_a_parent!"); 690 debug!(parent: &p, foo = ?3, bar.baz = %2, quux = false); 691 debug!(parent: &p, foo = 3, bar.baz = 2, quux = false); 692 debug!(parent: &p, foo = 3, bar.baz = 3,); 693 debug!(parent: &p, "foo"); 694 debug!(parent: &p, "foo: {}", 3); 695 debug!(parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 696 debug!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 697 debug!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 698 debug!(parent: &p, { foo = 2, bar.baz = 78 }, "quux"); 699 debug!(parent: &p, { foo = ?2, bar.baz = %78 }, "quux"); 700 debug!(target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); 701 debug!(target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); 702 debug!(target: "foo_events", parent: &p, "foo"); 703 debug!(target: "foo_events", parent: &p, "foo: {}", 3); 704 debug!(target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 705 debug!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 706 debug!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 707 debug!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); 708 } 709 710 #[test] 711 fn info_with_parent() { 712 let p = span!(Level::TRACE, "im_a_parent!"); 713 info!(parent: &p, foo = ?3, bar.baz = %2, quux = false); 714 info!(parent: &p, foo = 3, bar.baz = 2, quux = false); 715 info!(parent: &p, foo = 3, bar.baz = 3,); 716 info!(parent: &p, "foo"); 717 info!(parent: &p, "foo: {}", 3); 718 info!(parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 719 info!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 720 info!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 721 info!(parent: &p, { foo = 2, bar.baz = 78 }, "quux"); 722 info!(parent: &p, { foo = ?2, bar.baz = %78 }, "quux"); 723 info!(target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); 724 info!(target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); 725 info!(target: "foo_events", parent: &p, "foo"); 726 info!(target: "foo_events", parent: &p, "foo: {}", 3); 727 info!(target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 728 info!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 729 info!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 730 info!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); 731 } 732 733 #[test] 734 fn warn_with_parent() { 735 let p = span!(Level::TRACE, "im_a_parent!"); 736 warn!(parent: &p, foo = ?3, bar.baz = %2, quux = false); 737 warn!(parent: &p, foo = 3, bar.baz = 2, quux = false); 738 warn!(parent: &p, foo = 3, bar.baz = 3,); 739 warn!(parent: &p, "foo"); 740 warn!(parent: &p, "foo: {}", 3); 741 warn!(parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 742 warn!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 743 warn!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 744 warn!(parent: &p, { foo = 2, bar.baz = 78 }, "quux"); 745 warn!(parent: &p, { foo = ?2, bar.baz = %78 }, "quux"); 746 warn!(target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); 747 warn!(target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); 748 warn!(target: "foo_events", parent: &p, "foo"); 749 warn!(target: "foo_events", parent: &p, "foo: {}", 3); 750 warn!(target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 751 warn!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 752 warn!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 753 warn!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); 754 } 755 756 #[test] 757 fn error_with_parent() { 758 let p = span!(Level::TRACE, "im_a_parent!"); 759 error!(parent: &p, foo = ?3, bar.baz = %2, quux = false); 760 error!(parent: &p, foo = 3, bar.baz = 2, quux = false); 761 error!(parent: &p, foo = 3, bar.baz = 3,); 762 error!(parent: &p, "foo"); 763 error!(parent: &p, "foo: {}", 3); 764 error!(parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 765 error!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 766 error!(parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 767 error!(parent: &p, { foo = 2, bar.baz = 78 }, "quux"); 768 error!(parent: &p, { foo = ?2, bar.baz = %78 }, "quux"); 769 error!(target: "foo_events", parent: &p, foo = 3, bar.baz = 2, quux = false); 770 error!(target: "foo_events", parent: &p, foo = 3, bar.baz = 3,); 771 error!(target: "foo_events", parent: &p, "foo"); 772 error!(target: "foo_events", parent: &p, "foo: {}", 3); 773 error!(target: "foo_events", parent: &p, { foo = 3, bar.baz = 80 }, "quux"); 774 error!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}", true); 775 error!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false); 776 error!(target: "foo_events", parent: &p, { foo = 2, bar.baz = 78, }, "quux"); 777 } 778 779 #[test] 780 fn field_shorthand_only() { 781 #[derive(Debug)] 782 struct Position { 783 x: f32, 784 y: f32, 785 } 786 let pos = Position { 787 x: 3.234, 788 y: -1.223, 789 }; 790 791 trace!(?pos.x, ?pos.y); 792 debug!(?pos.x, ?pos.y); 793 info!(?pos.x, ?pos.y); 794 warn!(?pos.x, ?pos.y); 795 error!(?pos.x, ?pos.y); 796 event!(Level::TRACE, ?pos.x, ?pos.y); 797 } 798 799 #[test] 800 fn callsite_macro_api() { 801 // This test should catch any inadvertent breaking changes 802 // caused by changes to the macro. 803 let _callsite = callsite! { 804 name: "test callsite", 805 kind: tracing::metadata::Kind::EVENT, 806 target: "test target", 807 level: tracing::Level::TRACE, 808 fields: foo, bar, 809 }; 810 let _callsite = callsite! { 811 name: "test callsite", 812 kind: tracing::metadata::Kind::SPAN, 813 level: tracing::Level::TRACE, 814 fields: foo, 815 }; 816 let _callsite = callsite! { 817 name: "test callsite", 818 kind: tracing::metadata::Kind::SPAN, 819 fields: foo, 820 }; 821 } 822