## 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 ... ```
20 lines
456 B
Rust
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)));
|
|
}
|