Move logger-setup to tsstats.logger

and handlers are now attached as desired in __main__.cli
This commit is contained in:
Thor77 2017-02-27 12:33:30 +01:00
parent 2753f548fe
commit 0033ce186f
3 changed files with 18 additions and 14 deletions

View File

@ -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)

View File

@ -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:

13
tsstats/logger.py Normal file
View File

@ -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)