A rust library for colorizing [tracing_error::SpanTrace
] objects in the style
of [color-backtrace
].
Add the following to your Cargo.toml
:
toml
[dependencies]
color-spantrace = "0.1"
tracing = "0.1.13"
tracing-error = "0.1.2"
tracing-subscriber = "0.2.5"
Setup a tracing subscriber with an ErrorLayer
:
```rust use tracingerror::ErrorLayer; use tracingsubscriber::{prelude::*, registry::Registry};
Registry::default().with(ErrorLayer::default()).init(); ```
Create spans and enter them:
```rust use tracing::instrument; use tracing_error::SpanTrace;
fn foo() -> SpanTrace { SpanTrace::capture() } ```
And finally colorize the SpanTrace
:
```rust use tracing_error::SpanTrace;
let spantrace = SpanTrace::capture(); println!("{}", colorspantrace::colorize(&span_trace)); ```
This example is taken from examples/usage.rs
:
```rust use tracing::instrument; use tracingerror::{ErrorLayer, SpanTrace}; use tracingsubscriber::{prelude::*, registry::Registry};
fn main() { Registry::default().with(ErrorLayer::default()).init();
let span_trace = one(42);
println!("{}", color_spantrace::colorize(&span_trace));
}
fn one(i: u32) -> SpanTrace { two() }
fn two() -> SpanTrace { SpanTrace::capture() } ```
This creates the following output
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.