Start implementing logging

This commit is contained in:
Grégory Soutadé 2014-12-15 22:30:49 +01:00
parent ba5bd75ac1
commit e69af5e675
2 changed files with 17 additions and 1 deletions

1
TODO
View File

@ -6,5 +6,4 @@ Limit hits/pages/downloads by rate
Automatic tests Automatic tests
Add Licence Add Licence
Free memory as soon as possible Free memory as soon as possible
gzip output files
different debug output levels different debug output levels

17
iwla.py
View File

@ -9,6 +9,7 @@ import pickle
import gzip import gzip
import importlib import importlib
import argparse import argparse
import logging
from calendar import monthrange from calendar import monthrange
from datetime import date from datetime import date
@ -127,6 +128,12 @@ class IWLA(object):
(conf.POST_HOOK_DIRECTORY , conf.post_analysis_hooks), (conf.POST_HOOK_DIRECTORY , conf.post_analysis_hooks),
(conf.DISPLAY_HOOK_DIRECTORY , conf.display_hooks)] (conf.DISPLAY_HOOK_DIRECTORY , conf.display_hooks)]
self.logger = logging.getLogger('iwla')
self.logger.setFormatter(logging.Formatter('%(name)s %(message)s'))
def setLoggerLevel(self, level):
self.logger.setLevel(level)
def getVersion(self): def getVersion(self):
return IWLA.IWLA_VERSION return IWLA.IWLA_VERSION
@ -651,6 +658,10 @@ if __name__ == '__main__':
parser.add_argument('-f', '--file', dest='file', parser.add_argument('-f', '--file', dest='file',
help='Analyse this log file') help='Analyse this log file')
parser.add_argument('-d', '--log-level', dest='loglevel',
default=logging.INFO,
help='Loglevel')
args = parser.parse_args() args = parser.parse_args()
if args.clean_output: if args.clean_output:
@ -659,6 +670,12 @@ if __name__ == '__main__':
iwla = IWLA() iwla = IWLA()
numeric_level = getattr(logging, args.loglevel.upper(), None)
if not isinstance(numeric_level, int):
raise ValueError('Invalid log level: %s' % (args.loglevel))
iwla.setLoggerLevel(numeric_level)
required_conf = ['analyzed_filename', 'domain_name'] required_conf = ['analyzed_filename', 'domain_name']
if not validConfRequirements(required_conf, iwla, 'Main Conf'): if not validConfRequirements(required_conf, iwla, 'Main Conf'):
sys.exit(0) sys.exit(0)