2011-03-22 14:06:51 -07:00
|
|
|
import os
|
|
|
|
|
2011-03-22 10:10:19 -07:00
|
|
|
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,
|
2011-03-23 10:47:30 -07:00
|
|
|
'pypath': None,
|
2011-03-22 14:06:51 -07:00
|
|
|
}
|
|
|
|
|
2011-03-23 10:51:54 -07:00
|
|
|
try:
|
|
|
|
with open(os.path.expanduser('~/.config/interp.json')) as config_file:
|
|
|
|
d = json.load(config_file)
|
|
|
|
except IOError as e:
|
|
|
|
d = {}
|
2011-03-22 14:06:51 -07:00
|
|
|
|
|
|
|
config = dict(default_config.items() + d.items())
|
2011-03-22 10:10:19 -07:00
|
|
|
|
|
|
|
logger = logging.getLogger('interp')
|
2011-03-22 14:06:51 -07:00
|
|
|
logger.setLevel(LEVELS[config['level']])
|
2011-03-22 10:10:19 -07:00
|
|
|
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'])
|
2011-03-22 10:10:19 -07:00
|
|
|
handler.setFormatter(my_format)
|
|
|
|
logger.addHandler(handler)
|
2011-05-04 19:23:27 -07:00
|
|
|
|
|
|
|
|
|
|
|
__version__ = '0.2'
|