config: Try to create the logs directory before setting up error logs.

This commit is contained in:
Emmanuel Gil Peyrot 2018-07-19 12:03:40 +02:00
parent 31ec0564e7
commit c1bc46cb2c

View file

@ -594,14 +594,20 @@ def setup_logging():
LOG_DIR = config.get('log_dir')
LOG_DIR = Path(LOG_DIR).expanduser() if LOG_DIR else xdg.DATA_HOME / 'logs'
if config.get('log_errors'):
LOGGING_CONFIG['root']['handlers'].append('error')
LOGGING_CONFIG['handlers']['error'] = {
'level': 'ERROR',
'class': 'logging.FileHandler',
'filename': str(LOG_DIR / 'errors.log'),
'formatter': 'simple',
}
logging.disable(logging.WARNING)
try:
LOG_DIR.mkdir(parents=True, exist_ok=True)
except OSError:
# We cant really log any error here, because logging isnt setup yet.
pass
else:
LOGGING_CONFIG['root']['handlers'].append('error')
LOGGING_CONFIG['handlers']['error'] = {
'level': 'ERROR',
'class': 'logging.FileHandler',
'filename': str(LOG_DIR / 'errors.log'),
'formatter': 'simple',
}
logging.disable(logging.WARNING)
if options.debug:
LOGGING_CONFIG['root']['handlers'].append('debug')