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

Added support for quickmain to use log crate. (Address #165) #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dgrnbrg
Copy link
Contributor

@dgrnbrg dgrnbrg commented Sep 6, 2017

  • Added crate feature quickmain_log

When quickmain_log is enabled, the quick_main! entry point writes
the terminating error chain to log::error! instead of stdout.

Solves #165.

* Added crate feature `quickmain_log`

When `quickmain_log` is enabled, the `quick_main!` entry point writes
the terminating error chain to `log::error!` instead of stdout.
@Yamakaky
Copy link
Contributor

Hum, not sure it's needed... It's a 5 lines function, it's easy to copy if you want more customization.

@dgrnbrg
Copy link
Contributor Author

dgrnbrg commented Sep 10, 2017

I think that this is really valuable for continuing to mature rust. The quick_main! macro is used all over, because it's essentially an adapter that lets you write natively error-chaining libs with the boilerplate generated for you.

For users like me, our systems make extensive use of logging & error-chain. What this really does is makes it easy to write quick CLI tools and take advantage of error-chain & the logging already supported in the application.

The motivation here is that often, one needs to run applications unattended, and this allows boilerplate-free programs to have the reason they terminated in their log file. So, to me, the reason this is valuable is that it handles the 99% case of users who are using the standard log crate, since the termination reason shows up in the log file, plus it keeps the boilerplate down to zero.

@Yamakaky
Copy link
Contributor

Sorry for the delay. Could you update the files?

#[cfg(feature = "quickmain_log")]
fn print_error_helper<K,E: ::ChainedError<ErrorKind=K>>(e: &E) {
{ error!("{}", ::ChainedError::display_chain(e)) }
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you do one function instead? It should work without the helper

@rusterize
Copy link

@Yamakaky what do you think about adding a set of functions to log erros (using the log crate) that are added to the ResultExt trait? The functions would be:

loge(): prints the error and the cause chain using error!
logw(): same with warn!
logi(): same with info!
logd(): same with debug!
?

It is often that I want to log some errors as they happen without adding a lot of boilerplate if/match and calls to display_error. The functions would be used like chain_err(..) whenever the user wants to log that error at the spot.

something like:

fun_returning_result().chain_err(|| MyCustomErr("some info')).loge()?

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

Successfully merging this pull request may close these issues.

None yet

3 participants