-
Notifications
You must be signed in to change notification settings - Fork 111
Added support for quickmain to use log
crate. (Address #165)
#216
base: master
Are you sure you want to change the base?
Conversation
* 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.
Hum, not sure it's needed... It's a 5 lines function, it's easy to copy if you want more customization. |
I think that this is really valuable for continuing to mature rust. The 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 |
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)) } | ||
} |
There was a problem hiding this comment.
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
@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:
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 something like:
|
quickmain_log
When
quickmain_log
is enabled, thequick_main!
entry point writesthe terminating error chain to
log::error!
instead of stdout.Solves #165.