Struct color_backtrace::BacktracePrinter
source · pub struct BacktracePrinter { /* private fields */ }
Expand description
Pretty-printer for backtraces and PanicInfo
structs.
Implementations§
source§impl BacktracePrinter
impl BacktracePrinter
Builder functions.
sourcepub fn new() -> Self
pub fn new() -> Self
Alias for BacktracePrinter::default
.
Examples found in repository?
More examples
sourcepub fn color_scheme(self, colors: ColorScheme) -> Self
pub fn color_scheme(self, colors: ColorScheme) -> Self
Alter the color scheme.
Defaults to ColorScheme::classic()
.
sourcepub fn message(self, message: impl Into<String>) -> Self
pub fn message(self, message: impl Into<String>) -> Self
Controls the “greeting” message of the panic.
Defaults to "The application panicked (crashed)"
.
sourcepub fn verbosity(self, v: Verbosity) -> Self
pub fn verbosity(self, v: Verbosity) -> Self
Controls the verbosity level used when installed as panic handler.
Defaults to Verbosity::from_env()
.
sourcepub fn lib_verbosity(self, v: Verbosity) -> Self
pub fn lib_verbosity(self, v: Verbosity) -> Self
Controls the lib verbosity level used when formatting user provided traces.
Defaults to Verbosity::lib_from_env()
.
sourcepub fn strip_function_hash(self, strip: bool) -> Self
pub fn strip_function_hash(self, strip: bool) -> Self
Controls whether the hash part of functions is stripped.
Defaults to false
.
sourcepub fn print_addresses(self, val: bool) -> Self
pub fn print_addresses(self, val: bool) -> Self
Controls whether addresses (or module offsets if available) should be printed.
Defaults to false
.
sourcepub fn add_frame_filter(self, filter: Box<FilterCallback>) -> Self
pub fn add_frame_filter(self, filter: Box<FilterCallback>) -> Self
Add a custom filter to the set of frame filters
Filters are run in the order they are added.
Example
use color_backtrace::{default_output_stream, BacktracePrinter};
BacktracePrinter::new()
.add_frame_filter(Box::new(|frames| {
frames.retain(|x| matches!(&x.name, Some(n) if !n.starts_with("blabla")))
}))
.install(default_output_stream());
sourcepub fn clear_frame_filters(self) -> Self
pub fn clear_frame_filters(self) -> Self
Clears all filters associated with this printer, including the default filter
source§impl BacktracePrinter
impl BacktracePrinter
Routines for putting the panic printer to use.
sourcepub fn install(self, out: impl WriteColor + Sync + Send + 'static)
pub fn install(self, out: impl WriteColor + Sync + Send + 'static)
Install the color_backtrace
handler with default settings.
Output streams can be created via default_output_stream()
or
using any other stream that implements termcolor::WriteColor
.
Examples found in repository?
More examples
sourcepub fn into_panic_handler(
self,
out: impl WriteColor + Sync + Send + 'static
) -> Box<dyn Fn(&PanicInfo<'_>) + Sync + Send + 'static>
pub fn into_panic_handler( self, out: impl WriteColor + Sync + Send + 'static ) -> Box<dyn Fn(&PanicInfo<'_>) + Sync + Send + 'static>
Create a color_backtrace
panic handler from this panic printer.
This can be used if you want to combine the handler with other handlers.
sourcepub fn print_trace(
&self,
trace: &Backtrace,
out: &mut impl WriteColor
) -> Result<(), Error>
pub fn print_trace( &self, trace: &Backtrace, out: &mut impl WriteColor ) -> Result<(), Error>
Pretty-prints a backtrace::Backtrace
to an output stream.
sourcepub fn format_trace_to_string(&self, trace: &Backtrace) -> Result<String, Error>
pub fn format_trace_to_string(&self, trace: &Backtrace) -> Result<String, Error>
Pretty-print a backtrace to a String
, using VT100 color codes.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
fn main() -> Result<(), std::io::Error> {
let trace = backtrace::Backtrace::new();
let printer = BacktracePrinter::default();
let str = printer.format_trace_to_string(&trace)?;
if cfg!(windows) {
println!(
"Warning: on Windows, you'll have to enable VT100 \
printing for your app in order for this to work \
correctly. This example doesn't do this."
);
}
println!("{}", str);
Ok(())
}
sourcepub fn print_panic_info(
&self,
pi: &PanicInfo<'_>,
out: &mut impl WriteColor
) -> Result<(), Error>
pub fn print_panic_info( &self, pi: &PanicInfo<'_>, out: &mut impl WriteColor ) -> Result<(), Error>
Pretty-prints a PanicInfo
struct to an output stream.
Trait Implementations§
source§impl Clone for BacktracePrinter
impl Clone for BacktracePrinter
source§fn clone(&self) -> BacktracePrinter
fn clone(&self) -> BacktracePrinter
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more