#colors #color #pretty-printer #printer #pretty #style

color-spantrace

A pretty printer for tracing_error::SpanTrace based on color-backtrace

7 releases

0.1.6 Dec 2, 2020
0.1.5 Dec 2, 2020
0.1.4 Jul 6, 2020
0.1.3 Jun 3, 2020
0.1.1 May 7, 2020

#50 in Command-line interface

Download history 10993/week @ 2021-02-26 9294/week @ 2021-03-05 9250/week @ 2021-03-12 12369/week @ 2021-03-19 12279/week @ 2021-03-26 11742/week @ 2021-04-02 13034/week @ 2021-04-09 11034/week @ 2021-04-16 12747/week @ 2021-04-23 8396/week @ 2021-04-30 13448/week @ 2021-05-07 13769/week @ 2021-05-14 14867/week @ 2021-05-21 12219/week @ 2021-05-28 13290/week @ 2021-06-04 13063/week @ 2021-06-11

48,654 downloads per month
Used in color-eyre

MIT/Apache

185KB
233 lines

color-spantrace

Build Status Latest Version Rust Documentation

A rust library for colorizing tracing_error::SpanTrace objects in the style of color-backtrace.

Setup

Add the following to your Cargo.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:

use tracing_error::ErrorLayer;
use tracing_subscriber::{prelude::*, registry::Registry};

Registry::default().with(ErrorLayer::default()).init();

Create spans and enter them:

use tracing::instrument;
use tracing_error::SpanTrace;

#[instrument]
fn foo() -> SpanTrace {
    SpanTrace::capture()
}

And finally colorize the SpanTrace:

use tracing_error::SpanTrace;

let span_trace = SpanTrace::capture();
println!("{}", color_spantrace::colorize(&span_trace));

Example

This example is taken from examples/usage.rs:

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

Full Format

Full format

License

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.

Dependencies

~1MB
~21K SLoC