tracing/tracing-macros/examples/factorial.rs
Mark Ingram 16806fc12c
examples: updates factorial to tracing 0.2 & set DEBUG level (#1182)
## Motivation

factorial dbg! example doesn't produce any stdout & is referencing tracing 0.1 crate

## Solution

update to path reference & set fmt max level DEBUG:

```
$ cargo run --example factorial
Jan 10 21:17:47.574 DEBUG factorial: n <= 1 value=false
Jan 10 21:17:47.575 DEBUG factorial: n <= 1 value=false
...
```
2021-01-27 14:05:21 -08:00

20 lines
456 B
Rust

//! Compare to the example given in the documentation for the `std::dbg` macro.
#![deny(rust_2018_idioms)]
use tracing_macros::dbg;
fn factorial(n: u32) -> u32 {
if dbg!(n <= 1) {
dbg!(1)
} else {
dbg!(n * factorial(n - 1))
}
}
fn main() {
let collector = tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.finish();
tracing::collect::with_default(collector, || dbg!(factorial(4)));
}