From b30e786b2f647151fbc358d185d13e45cbc75b84 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 23 Feb 2018 19:37:53 +0100 Subject: Logging facility configured by command line arguments --- jfr_playoff/logger.py | 15 +++++++++++++++ playoff.py | 7 +++++++ 2 files changed, 22 insertions(+) create mode 100644 jfr_playoff/logger.py diff --git a/jfr_playoff/logger.py b/jfr_playoff/logger.py new file mode 100644 index 0000000..8944e5b --- /dev/null +++ b/jfr_playoff/logger.py @@ -0,0 +1,15 @@ +import logging as log + + +class PlayoffLogger: + + @classmethod + def setup(cls, level): + log.basicConfig( + level=getattr(log, level), + streamhandler=log.StreamHandler(), + format='%(levelname)-8s %(name)-8s %(message)s') + + @classmethod + def get(cls, category=''): + return log.getLogger(category) diff --git a/playoff.py b/playoff.py index 6a2a8ff..16113fc 100644 --- a/playoff.py +++ b/playoff.py @@ -3,6 +3,7 @@ import traceback from jfr_playoff.filemanager import PlayoffFileManager from jfr_playoff.generator import PlayoffGenerator from jfr_playoff.settings import PlayoffSettings +from jfr_playoff.logger import PlayoffLogger def main(): @@ -25,6 +26,12 @@ def main(): type=str, nargs='?', default=None) arguments = arg_parser.parse_args() + PlayoffLogger.setup('ERROR' if arguments.quiet else ( + 'INFO' if arguments.verbose else ( + 'DEBUG' if arguments.debug else 'WARNING'))) + + PlayoffLogger.get().debug('started with arguments: %s', arguments) + settings = PlayoffSettings(arguments.config_file) interactive = settings.interactive -- cgit v1.2.3