diff options
Diffstat (limited to 'vendor/tracing-tree/examples/stderr.rs')
-rw-r--r-- | vendor/tracing-tree/examples/stderr.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/tracing-tree/examples/stderr.rs b/vendor/tracing-tree/examples/stderr.rs new file mode 100644 index 000000000..75880a376 --- /dev/null +++ b/vendor/tracing-tree/examples/stderr.rs @@ -0,0 +1,40 @@ +use tracing::{debug, info, instrument}; +use tracing_subscriber::{layer::SubscriberExt, registry::Registry}; +use tracing_tree::HierarchicalLayer; + +#[instrument] +fn nth_fibonacci(n: u64) -> u64 { + if n == 0 || n == 1 { + debug!("Base case"); + 1 + } else { + debug!("Recursing"); + nth_fibonacci(n - 1) + nth_fibonacci(n - 2) + } +} + +#[instrument] +fn fibonacci_seq(to: u64) -> Vec<u64> { + let mut sequence = vec![]; + + for n in 0..=to { + debug!("Pushing {n} fibonacci", n = n); + sequence.push(nth_fibonacci(n)); + } + + sequence +} + +fn main() { + let layer = HierarchicalLayer::default() + .with_indent_lines(true) + .with_indent_amount(2) + .with_bracketed_fields(true); + + let subscriber = Registry::default().with(layer); + tracing::subscriber::set_global_default(subscriber).unwrap(); + + let n = 5; + let sequence = fibonacci_seq(n); + info!("The first {} fibonacci numbers are {:?}", n, sequence); +} |