smbinterp/interp/__init__.py

41 lines
1002 B
Python

import os
import logging
import logging.handlers
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,
'pypath': None,
}
try:
with open(os.path.expanduser('~/.config/interp.json')) as config_file:
d = json.load(config_file)
except IOError as e:
d = {}
config = dict(default_config.items() + d.items())
logger = logging.getLogger('interp')
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['logbackup'])
handler.setFormatter(my_format)
logger.addHandler(handler)
__version__ = '0.2'