Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/athre0z/color-backtrace
Colorful panic backtraces for Rust
https://github.com/athre0z/color-backtrace
Last synced: 13 days ago
JSON representation
Colorful panic backtraces for Rust
- Host: GitHub
- URL: https://github.com/athre0z/color-backtrace
- Owner: athre0z
- License: apache-2.0
- Created: 2019-04-18T17:14:16.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-22T23:57:11.000Z (about 1 year ago)
- Last Synced: 2024-04-24T15:24:01.224Z (7 months ago)
- Language: Rust
- Size: 167 KB
- Stars: 548
- Watchers: 13
- Forks: 18
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
color-backtrace
===============[![Crates.io][crates-badge]][crates-url]
[![docs.rs][docs-badge]][docs-url]
[![MIT licensed][mit-badge]][mit-url]
[![Apache 2.0 licensed][apache-badge]][apache-url][crates-badge]: https://img.shields.io/crates/v/color-backtrace.svg
[crates-url]: https://crates.io/crates/color-backtrace
[docs-badge]: https://docs.rs/color-backtrace/badge.svg
[docs-url]: https://docs.rs/color-backtrace/
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
[mit-url]: LICENSE-MIT
[apache-badge]: https://img.shields.io/badge/license-Apache%202.0-blue.svg
[apache-url]: LICENSE-APACHEA Rust library that makes panics a little less painful by nicely colorizing them
and printing the relevant source snippets.```toml
[dependencies]
color-backtrace = { version = "0.6" }
```To enable it, simply place this code somewhere in your app initialization code:
```rust
color_backtrace::install();
```If you want to customize some settings, you can instead do:
```rust
use color_backtrace::{default_output_stream, BacktracePrinter};
BacktracePrinter::new().message("Custom message!").install(default_output_stream());
```### Features
- Colorize backtraces to be easier on the eyes
- Show source snippets if source files are found on disk
- Print frames of application code vs dependencies in different color
- Hide all the frames after the panic was already initiated
- Hide language runtime initialization frames### Usage in tests
Unfortunately, defining custom init functions run before tests are started is
currently [not supported in Rust](https://github.com/rust-lang/rfcs/issues/1664).
Since initializing color-backtrace in each and every test is tedious even when
wrapping it into a function, I recommended using the
[ctor](https://crates.io/crates/ctor) crate for this.Somewhere, preferably in your crate's main module, put the following code:
```rust
#[cfg(test)]
mod tests {
use ctor::ctor;#[ctor]
fn init_color_backtrace() {
color_backtrace::install();
}
}
```You can also do this outside of a `#[cfg(test)]` section, in which case the
panic handler is installed for both test and regular runs.### Screenshot
![Screenshot](https://i.imgur.com/jLznHxp.png)