added a config file
This commit is contained in:
parent
f600f8a2f2
commit
465bc0d819
@ -1,18 +1,35 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
config = {
|
|
||||||
'filename': '/tmp/interpolatoryawesome.log',
|
LEVELS = {'debug': logging.DEBUG,
|
||||||
'level': logging.INFO,
|
'info': logging.INFO,
|
||||||
'size' : 1024000,
|
'warning': logging.WARNING,
|
||||||
'backupCount': 10,
|
'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 = 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')
|
my_format = logging.Formatter('%(asctime)s %(levelname)s (%(process)d) %(filename)s %(funcName)s:%(lineno)d %(message)s')
|
||||||
handler = logging.handlers.RotatingFileHandler(
|
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)
|
handler.setFormatter(my_format)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
Loading…
Reference in New Issue
Block a user