Skip to content

Instantly share code, notes, and snippets.

@bgruening
Created April 14, 2015 08:00
Show Gist options
  • Save bgruening/c6129fa28553c67de64c to your computer and use it in GitHub Desktop.
Save bgruening/c6129fa28553c67de64c to your computer and use it in GitHub Desktop.
python argparse and logging
import logging
import argparse
...
parser.add_argument('-v', '--verbose', action="count", help="Set verbose lever by specifying multiple -v values.")
...
logger = logging.StreamHandler()
if not args.verbose:
logger.setLevel('ERROR')
elif args.verbose == 1:
logger.setLevel('WARNING')
elif args.verbose == 2:
logger.setLevel('INFO')
else:
logger.setLevel('DEBUG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment