Last active
March 3, 2017 09:42
-
-
Save logc/e3382f6a1bd9870262aa094aba9b60bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_command_line(): | |
"""Defines and parses command line arguments""" | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-v', '--verbose', action='count', default=0) | |
return parser.parse_args() | |
def configure_logging(args): | |
"""Configures logging as specified by the author and the user""" | |
levels = [logging.WARNING, logging.INFO, logging.DEBUG] | |
level = levels[args.verbose % len(levels)] | |
logging.basicConfig( | |
level=level, | |
format=("%(asctime)s %(levelname)s %(name)s.%(funcName)s " | |
"[%(filename)s:%(lineno)s] %(message)s")) |
... and use getLogger
in your classes like this:
class Example(object):
def __init__(self):
self.logger = logging.getLogger(self.__class__.__name__)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run a script that contains these functions as
or