added a config file

This commit is contained in:
Stephen McQuay 2011-03-22 15:06:51 -06:00
parent f600f8a2f2
commit 465bc0d819

View File

@ -1,18 +1,35 @@
import os
import logging
import logging.handlers
import json
config = {
'filename': '/tmp/interpolatoryawesome.log',
'level': logging.INFO,
'size' : 1024000,
'backupCount': 10,
}
LEVELS = {'debug': logging.DEBUG,
'info': logging.INFO,
'warning': logging.WARNING,
'error': logging.ERROR,
'critical': logging.CRITICAL}
default_config = {
'filename': '/tmp/interp.log',
'level': 'debug',
'size' : 102400,
'logbackup': 10,
}
with open(os.path.expanduser('~/.config/interp.json')) as config_file:
d = json.load(config_file)
config = dict(default_config.items() + d.items())
print config
logger = logging.getLogger('interp')
logger.setLevel(config['level'])
logger.setLevel(LEVELS[config['level']])
my_format = logging.Formatter('%(asctime)s %(levelname)s (%(process)d) %(filename)s %(funcName)s:%(lineno)d %(message)s')
handler = logging.handlers.RotatingFileHandler(
config['filename'], maxBytes = config['size'] * 1024, backupCount = config['backupCount'])
config['filename'], maxBytes = config['size'] * 1024, backupCount = config['logbackup'])
handler.setFormatter(my_format)
logger.addHandler(handler)