diff --git a/tsstats/__init__.py b/tsstats/__init__.py index 0092454..40a96af 100644 --- a/tsstats/__init__.py +++ b/tsstats/__init__.py @@ -1,15 +1 @@ # -*- coding: utf-8 -*- - -import logging - -logger = logging.getLogger('tsstats') -logger.setLevel(logging.INFO) - -fh = logging.FileHandler('debug.txt', 'w', delay=True) -fh.setLevel(logging.DEBUG) - -ch = logging.StreamHandler() -ch.setLevel(logging.INFO) - -logger.addHandler(fh) -logger.addHandler(ch) diff --git a/tsstats/__main__.py b/tsstats/__main__.py index ec7938a..b31d475 100644 --- a/tsstats/__main__.py +++ b/tsstats/__main__.py @@ -8,6 +8,7 @@ from os.path import abspath, exists from tsstats import config from tsstats.exceptions import InvalidConfiguration from tsstats.log import parse_logs +from tsstats.logger import file_handler, stream_handler from tsstats.template import render_servers from tsstats.utils import transform_pretty_identmap @@ -67,8 +68,12 @@ def cli(): def main(configuration): + # setup logging if configuration.getboolean('General', 'debug'): logger.setLevel(logging.DEBUG) + # attach handlers + logger.addHandler(file_handler) + logger.addHandler(stream_handler) idmap = configuration.get('General', 'idmap') if idmap: diff --git a/tsstats/logger.py b/tsstats/logger.py new file mode 100644 index 0000000..2e53994 --- /dev/null +++ b/tsstats/logger.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +import logging + +# setup logger +logger = logging.getLogger('tsstats') +logger.setLevel(logging.INFO) + +# define handlers +file_handler = logging.FileHandler('debug.txt', 'w', delay=True) +file_handler.setLevel(logging.DEBUG) + +stream_handler = logging.StreamHandler() +stream_handler.setLevel(logging.INFO)