Skip to content

Instantly share code, notes, and snippets.

@MattMS MattMS/logging argparse.py
Last active Aug 29, 2015

Embed
What would you like to do?
Get logging level from argparse
import argparse
import logging
logger = logging.getLogger(__name__)
kwargs = dict(level=logging.INFO)
if '__main__' == __name__:
parser = argparse.ArgumentParser(description='')
parser.add_argument(
'--log-level',
dest='log_level',
default='',
type=str,
help='Minimum level of logging to keep.'
)
args = parser.parse_args()
log_levels = ['DEBUG', 'INFO']
given_level = args.log_level.upper()
if given_level in log_levels:
kwargs['level'] = getattr(logging, given_level)
logging.basicConfig(**kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.