smbinterp/interp/__init__.py

37 lines
955 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,
}
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(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)