snafu icon indicating copy to clipboard operation
snafu copied to clipboard

Feature request: snafu::report_log

Open jaskij opened this issue 7 months ago • 4 comments

Basically, something like snafu::report, but that uses log for output, possibly a configurable level (as not all Errors are errors).

jaskij avatar May 28 '25 20:05 jaskij

As a next step, implementing log::kv::ToValue on snafu::Report so we get the values structured would be amazing. I'm aware of #407, so this needs further discussion on details.

jaskij avatar May 28 '25 20:05 jaskij

Given an arbitrary impl std::error::Error, what would you expect snafu::report_log to do / output?

shepmaster avatar May 28 '25 20:05 shepmaster

That... is a good question. My main intent here was for snafu::report_log to specifically output contents similar to snafu::report. For consistency's sake, I'd say that it should behave similarly to snafu::report, which seems to convert the impl std::error::Error to snafu::Raport and output that.

My original intent was for this to be output from within a controlled library crate - as a shim to work together with tracing::instrument without introducing new dependencies or trait implementations.

I now realize that, without the log::kv::ToValue support for some form of structured logging, this wouldn't make much sense. Can't really stuff the nice chain display you have into regular, single-line, logs.

jaskij avatar May 28 '25 21:05 jaskij

I now realize that, without the log::kv::ToValue support for some form of structured logging, this wouldn't make much sense. Can't really stuff the nice chain display you have into regular, single-line, logs.

I think this is getting towards my point. Can you provide any kind of example of an error and what the corresponding log output would be? If you need it, use tracing_subscriber::fmt::fmt as a concrete subscriber.

shepmaster avatar May 29 '25 14:05 shepmaster

I only realized I haven't replied to this issue because I'm cleaning up my GH notifications. Given that, and that I'm not really using snafu, closing this issue.

jaskij avatar Sep 30 '25 15:09 jaskij