color-spantrace 0.1.1

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

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