rust-lang-deprecated / error-chain

Error boilerplate for Rust
Apache License 2.0
730 stars 111 forks source link

Adding a crate feature to integrate with logging #165

Open dgrnbrg opened 7 years ago

dgrnbrg commented 7 years ago

My application uses the general Rust log crate, as well as lots of error_chain. I'd like to contribute a feature for this crate called log, which causes quick_main! to write its output to error! instead of (or in addition to) stderr when the feature is enabled.

Additionally, I think it could be useful to have calls to chain_err write their information at the debug level; however, this could be overly verbose. At the same time, chain_err closures contain a lot of useful information that could reduce the burden to write useful logging statements, but still be able to debug an application more easily.

Would you be willing to accept this contribution?

Yamakaky commented 7 years ago

Hum, interesting idea! It should just be optional so that people who don't need it don't pay for it.

We should take into account that all errors don't have the same impact, so maybe it should be configurable?

dgrnbrg commented 7 years ago

Here's what I think makes sense:

Logging potentially caught errors to debug should mostly be useful for situations in which errors are being used, but logging hasn't been written. As a result, I think using any level more urgent than debug or trace isn't desirable, as this feature would make it easier to get a bit more debugging context without recompiling; it wouldn't replace proper logging.

dgrnbrg commented 7 years ago

Hello, I've created a pull request finally to solve this. I gave up for a while without realizing that #[cfg()] attributes are silently ignored or have different behavior on expressions within macros than on top level functions.