mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-29 05:52:13 +00:00
final prep before release
This commit is contained in:
parent
2e78274bdb
commit
208cb84f69
@ -15,7 +15,7 @@ of [`color-backtrace`].
|
|||||||
|
|
||||||
Add the following to your `Cargo.toml`:
|
Add the following to your `Cargo.toml`:
|
||||||
|
|
||||||
```
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
color-spantrace = "0.1"
|
color-spantrace = "0.1"
|
||||||
tracing = "0.1.13"
|
tracing = "0.1.13"
|
||||||
@ -47,6 +47,9 @@ fn foo() -> SpanTrace {
|
|||||||
And finally colorize the `SpanTrace`:
|
And finally colorize the `SpanTrace`:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use tracing_error::SpanTrace;
|
||||||
|
|
||||||
|
let span_trace = SpanTrace::capture();
|
||||||
println!("{}", color_spantrace::colorize(&span_trace));
|
println!("{}", color_spantrace::colorize(&span_trace));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
62
src/lib.rs
62
src/lib.rs
@ -1,3 +1,50 @@
|
|||||||
|
//! 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.1"
|
||||||
|
//! tracing = "0.1.13"
|
||||||
|
//! tracing-error = "0.1.2"
|
||||||
|
//! tracing-subscriber = "0.2.5"
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! 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));
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! [`tracing_error::SpanTrace`]: https://docs.rs/tracing-error/*/tracing_error/struct.SpanTrace.html
|
||||||
|
//! [`color-backtrace`]: https://github.com/athre0z/color-backtrace
|
||||||
#![doc(html_root_url = "https://docs.rs/color-spantrace/0.1.0")]
|
#![doc(html_root_url = "https://docs.rs/color-spantrace/0.1.0")]
|
||||||
use ansi_term::{Color::*, Style};
|
use ansi_term::{Color::*, Style};
|
||||||
use std::env;
|
use std::env;
|
||||||
@ -7,6 +54,21 @@ use std::io::{BufRead, BufReader, ErrorKind};
|
|||||||
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
||||||
use tracing_error::SpanTrace;
|
use tracing_error::SpanTrace;
|
||||||
|
|
||||||
|
/// Display a [`SpanTrace`] with colors and source
|
||||||
|
///
|
||||||
|
/// This function returns an `impl Display` type which can be then used in place of the original
|
||||||
|
/// SpanTrace when writing it too the screen or buffer.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use tracing_error::SpanTrace;
|
||||||
|
///
|
||||||
|
/// let span_trace = SpanTrace::capture();
|
||||||
|
/// println!("{}", color_spantrace::colorize(&span_trace));
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// [`SpanTrace`]: https://docs.rs/tracing-error/*/tracing_error/struct.SpanTrace.html
|
||||||
pub fn colorize(span_trace: &SpanTrace) -> impl fmt::Display + '_ {
|
pub fn colorize(span_trace: &SpanTrace) -> impl fmt::Display + '_ {
|
||||||
ColorSpanTrace { span_trace }
|
ColorSpanTrace { span_trace }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user