Add logging options to argparse automatically
# main.py
import argparse
import logging
import arglog
if __name__ == '__main__':
parser = argparse.ArgumentParser()
arglog.patch(parser)
args = parser.parse_args()
This will trigger the same effect as running:
logging.basicConfig(level='<level name>')
However, you now also have a new CLI option for your program:
$ python main.py --loglevel=WARNING
All of the logging levels are supported, INFO
, DEBUG
and so on.