blob: 0a1bcde28158a82abb48040d26efda4233fbb820 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
color-spantrace
===============
[![Build Status][actions-badge]][actions-url]
[![Latest Version](https://img.shields.io/crates/v/color-spantrace.svg)](https://crates.io/crates/color-spantrace)
[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/color-spantrace)
[actions-badge]: https://github.com/yaahc/color-spantrace/workflows/Continuous%20integration/badge.svg
[actions-url]: https://github.com/yaahc/color-spantrace/actions?query=workflow%3A%22Continuous+integration%22
A rust library for colorizing [`tracing_error::SpanTrace`] objects in the style
of [`color-backtrace`].
## Setup
Add the following to your `Cargo.toml`:
```toml
[dependencies]
color-spantrace = "0.2"
tracing = "0.1"
tracing-error = "0.2"
tracing-subscriber = "0.3"
```
Setup a tracing subscriber with an `ErrorLayer`:
```rust
use tracing_error::ErrorLayer;
use tracing_subscriber::{prelude::*, registry::Registry};
Registry::default().with(ErrorLayer::default()).init();
```
Create spans and enter them:
```rust
use tracing::instrument;
use tracing_error::SpanTrace;
#[instrument]
fn foo() -> SpanTrace {
SpanTrace::capture()
}
```
And finally colorize the `SpanTrace`:
```rust
use tracing_error::SpanTrace;
let span_trace = SpanTrace::capture();
println!("{}", color_spantrace::colorize(&span_trace));
```
## Example
This example is taken from `examples/usage.rs`:
```rust
use tracing::instrument;
use tracing_error::{ErrorLayer, SpanTrace};
use tracing_subscriber::{prelude::*, registry::Registry};
#[instrument]
fn main() {
Registry::default().with(ErrorLayer::default()).init();
let span_trace = one(42);
println!("{}", color_spantrace::colorize(&span_trace));
}
#[instrument]
fn one(i: u32) -> SpanTrace {
two()
}
#[instrument]
fn two() -> SpanTrace {
SpanTrace::capture()
}
```
This creates the following output
### Minimal Format
![minimal format](./pictures/minimal.png)
### Full Format
![Full format](./pictures/full.png)
#### License
<sup>
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
</sup>
<br>
<sub>
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.
</sub>
[`tracing_error::SpanTrace`]: https://docs.rs/tracing-error/*/tracing_error/struct.SpanTrace.html
[`color-backtrace`]: https://github.com/athre0z/color-backtrace
|