-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from eyre-rs/color-spantrace
Add color-spantrace to monorepo
- Loading branch information
Showing
13 changed files
with
717 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[workspace] | ||
members = [ | ||
"color-spantrace", | ||
"eyre" | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
<!-- next-header --> | ||
|
||
## [Unreleased] - ReleaseDate | ||
|
||
## [0.2.0] - 2022-01-12 | ||
### Changed | ||
- Updated dependency versions to match latest tracing versions | ||
|
||
## [0.1.6] - 2020-12-02 | ||
### Fixed | ||
- Ignore all io errors when resolving source files instead of only file not | ||
found errors | ||
|
||
## [v0.1.5] - 2020-12-01 | ||
### Added | ||
- Support custom color themes for spantrace format | ||
|
||
<!-- next-url --> | ||
[Unreleased]: https://github.com/eyre-rs/color-spantrace/compare/v0.2.0...HEAD | ||
[0.2.0]: https://github.com/eyre-rs/color-spantrace/compare/v0.1.6...v0.2.0 | ||
[0.1.6]: https://github.com/eyre-rs/color-spantrace/compare/v0.1.5...v0.1.6 | ||
[v0.1.5]: https://github.com/eyre-rs/color-spantrace/releases/tag/v0.1.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
[package] | ||
name = "color-spantrace" | ||
version = "0.2.0" | ||
description = "A pretty printer for tracing_error::SpanTrace based on color-backtrace" | ||
documentation = "https://docs.rs/color-spantrace" | ||
|
||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
readme = { workspace = true } | ||
rust-version = { workspace = true } | ||
|
||
[dependencies] | ||
tracing-error = "0.2.0" | ||
tracing-core = "0.1.21" | ||
owo-colors = "3.2.0" | ||
once_cell = { workspace = true } | ||
|
||
[dev-dependencies] | ||
tracing-subscriber = "0.3.4" | ||
tracing = "0.1.29" | ||
ansi-parser = "0.8" # used for testing color schemes | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
rustdoc-args = ["--cfg", "docsrs"] | ||
|
||
[package.metadata.release] | ||
dev-version = false | ||
|
||
[[package.metadata.release.pre-release-replacements]] | ||
file = "CHANGELOG.md" | ||
search = "Unreleased" | ||
replace="{{version}}" | ||
|
||
[[package.metadata.release.pre-release-replacements]] | ||
file = "src/lib.rs" | ||
search = "#!\\[doc\\(html_root_url.*" | ||
replace = "#![doc(html_root_url = \"https://docs.rs/{{crate_name}}/{{version}}\")]" | ||
exactly = 1 | ||
|
||
[[package.metadata.release.pre-release-replacements]] | ||
file = "CHANGELOG.md" | ||
search = "\\.\\.\\.HEAD" | ||
replace="...{{tag_name}}" | ||
exactly = 1 | ||
|
||
[[package.metadata.release.pre-release-replacements]] | ||
file = "CHANGELOG.md" | ||
search = "ReleaseDate" | ||
replace="{{date}}" | ||
|
||
[[package.metadata.release.pre-release-replacements]] | ||
file="CHANGELOG.md" | ||
search="<!-- next-header -->" | ||
replace="<!-- next-header -->\n\n## [Unreleased] - ReleaseDate" | ||
exactly=1 | ||
|
||
[[package.metadata.release.pre-release-replacements]] | ||
file="CHANGELOG.md" | ||
search="<!-- next-url -->" | ||
replace="<!-- next-url -->\n[Unreleased]: https://github.com/eyre-rs/{{crate_name}}/compare/{{tag_name}}...HEAD" | ||
exactly=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-APACHE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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/eyre-rs/color-spantrace/workflows/Continuous%20integration/badge.svg | ||
[actions-url]: https://github.com/eyre-rs/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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() | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.