RUST_BACKTRACE output targets

For the past few weeks I've been making a few daemons able to run as Windows services (which do not have standard input/output). While working on the last one I made a copy'n'paste error (see this post) and the experience has left me realizing that there may be a few ergonomic improvements for non-std{out/err} environments to be made.

It would be nice if there was a way to tell RUST_BACKTRACE to write its backtrace to other targets. For instance, on Windows there's a OutputDebugString() function that will send the output to a debugger [if one is attached]. But more generally, it would be helpful it it was possible to dump the backtrace to a file.

Something like RUST_BACKTRACE_TARGET=windbgstr or RUST_BACKTRACE_TARGET=file:C:\Temp\myservice.backtrace.

Neither of these would require much in terms of space or complexity, though I realize adding fallible file system I/O to a backtrace dump is a little sketchy..

Ideally, I'd love to see a mechanism to wire up stderr to a logging target, so that panics, backtraces, and anything else all will go there.

2 Likes

You can use std::panic::set_hook to send panics and backtraces to whatever output you want.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.