-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print a backtrace/spantrace to debug logs not to stderr #130
Comments
I tried a few more things, and as far as I can tell: A spantrace is mostly useful if you have A backtrace is more likely to be what I want, but the I think what I want is something like this: if std::env::var("RUST_BACKTRACE").is_err() {
std::env::set_var("RUST_BACKTRACE", "1");
}
// Rest of program execution goes here.
// Print the backtrace.
debug!("Run result: {result}");
if let Err(report) = result.as_mut() {
if let Some(handler) = report.handler_mut().downcast_mut::<color_eyre::Handler>() {
if let Some(backtrace) = handler.backtrace_mut() {
// Remove the backtrace.
let _ = backtrace.take();
}
}
}
// Return the program result, not printing the backtrace.
return result; but |
Sorry if this is in the docs/examples and I missed it, but I'm struggling to work out how I would manually generate a backtrace or a spantrace from a
color_eyre::Result
.The use-case is a user-facing CLI, where I write trace logs to a file. When something goes wrong printing a backtrace tends to confuse users, and makes them even more likely to miss the
Suggestion:
I added that tells them exactly what to do 😁However the backtrace is useful for me, when I didn't add enough context to each layer of the error stack to see where the error propagated.
The CLI tells people to ask for support and attach the log file in the issue, and so I'd like to
tracing::debug!()
log the spantrace so it persists in the log file.The text was updated successfully, but these errors were encountered: