smbinterp/interp/__init__.py

36 lines
937 B
Python
Raw Normal View History

2011-03-22 14:06:51 -07:00
import os
import logging
import logging.handlers
2011-03-22 14:06:51 -07:00
import json
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())
2011-03-22 14:06:51 -07:00
print config
logger = logging.getLogger('interp')
2011-03-22 14:06:51 -07:00
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(
2011-03-22 14:06:51 -07:00
config['filename'], maxBytes = config['size'] * 1024, backupCount = config['logbackup'])
handler.setFormatter(my_format)
logger.addHandler(handler)