Description
First let me say I'm a big fan of defopt. I'd like to suggest a new feature related to #7 but simpler. defopt is designed to allow functions to be used as library functions from Python or as CLI programs. To incorporate logging for both cases requires some care. I'd like to suggest some small enhancements that would handle most of it.
- Have defopt do
if not logging.getLogger().handlers:
logging.getLogger().addHandler(logging.NullHandler(logging.WARN))
during module loading, as having some null handler avoids generating error messages from logging calls in libraries.
- Add kwargs to defopt.run() along the lines of:
log_level=logging.WARN
log_file=None
log_handler=None
for specifying those things from the main block to take effect only when functions are run from the defopt CLI.
- Add a switch argument to defopt.run() like
log_args=False
that could be set to enable a standard set of CLI args for logging config as if the function had the following in its argument list:
:param str log_level: choice of standard levels
:param str log_file: path to log file, or special constants 'stderr', 'stdout'
If this were added to defopt then fairly complete logging configuration would be available with minimal effort and w/o compromising the promise that defopt won't interfere with using your functions from Python.