Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Adding a crate feature to integrate with logging #165

Open
dgrnbrg opened this issue Jul 10, 2017 · 3 comments
Open

Adding a crate feature to integrate with logging #165

dgrnbrg opened this issue Jul 10, 2017 · 3 comments

Comments

@dgrnbrg
Copy link
Contributor

dgrnbrg commented Jul 10, 2017

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
Copy link
Contributor

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
Copy link
Contributor Author

dgrnbrg commented Jul 12, 2017

Here's what I think makes sense:

  • The entire bit of functionality is a crate feature, so it must be explicitly enabled (if not enabled, it changes nothing).
  • quick_main! uses error! instead of println! when the feature's enabled
  • chain_err prints the return value of its closure using debug!("{:?}", err) if it ends up actually chaining an error, and if the return value of the closure implements Debug (I think this is doable via Any for a runtime check whether it supports Debug).

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
Copy link
Contributor Author

dgrnbrg commented Sep 6, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants