Skip to content

Instantly share code, notes, and snippets.

@jorgeas80
Created October 12, 2015 14:20
Show Gist options
  • Save jorgeas80/ea9e08bcd56931a04ffc to your computer and use it in GitHub Desktop.
Save jorgeas80/ea9e08bcd56931a04ffc to your computer and use it in GitHub Desktop.
Logging level trick in Python
# Trick from https://www.reddit.com/r/Python/comments/3nctlm/what_python_tools_should_i_be_using_on_every
# The logging levels are actually integers with a 10 increment (DEBUG is 10, CRITICAL is 50)
parser.add_argument('-v', '--verbose', action='count', default=0)
parser.add_argument('-q', '--quiet', action='count', default=0)
logging_level = logging.WARN + 10*args.quiet - 10*args.verbose
# script -vv -> DEBUG
# script -v -> INFO
# script -> WARNING
# script -q -> ERROR
# script -qq -> CRITICAL
# script -qqq -> no logging at all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment