Skip to content

Instantly share code, notes, and snippets.

@logc
Last active March 3, 2017 09:42
Show Gist options
  • Save logc/e3382f6a1bd9870262aa094aba9b60bd to your computer and use it in GitHub Desktop.
Save logc/e3382f6a1bd9870262aa094aba9b60bd to your computer and use it in GitHub Desktop.
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"))
@logc
Copy link
Author

logc commented Oct 9, 2016

... 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