config: Try to create the logs directory before setting up error logs.
This commit is contained in:
parent
31ec0564e7
commit
c1bc46cb2c
1 changed files with 14 additions and 8 deletions
|
@ -594,14 +594,20 @@ def setup_logging():
|
||||||
LOG_DIR = config.get('log_dir')
|
LOG_DIR = config.get('log_dir')
|
||||||
LOG_DIR = Path(LOG_DIR).expanduser() if LOG_DIR else xdg.DATA_HOME / 'logs'
|
LOG_DIR = Path(LOG_DIR).expanduser() if LOG_DIR else xdg.DATA_HOME / 'logs'
|
||||||
if config.get('log_errors'):
|
if config.get('log_errors'):
|
||||||
LOGGING_CONFIG['root']['handlers'].append('error')
|
try:
|
||||||
LOGGING_CONFIG['handlers']['error'] = {
|
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
'level': 'ERROR',
|
except OSError:
|
||||||
'class': 'logging.FileHandler',
|
# We can’t really log any error here, because logging isn’t setup yet.
|
||||||
'filename': str(LOG_DIR / 'errors.log'),
|
pass
|
||||||
'formatter': 'simple',
|
else:
|
||||||
}
|
LOGGING_CONFIG['root']['handlers'].append('error')
|
||||||
logging.disable(logging.WARNING)
|
LOGGING_CONFIG['handlers']['error'] = {
|
||||||
|
'level': 'ERROR',
|
||||||
|
'class': 'logging.FileHandler',
|
||||||
|
'filename': str(LOG_DIR / 'errors.log'),
|
||||||
|
'formatter': 'simple',
|
||||||
|
}
|
||||||
|
logging.disable(logging.WARNING)
|
||||||
|
|
||||||
if options.debug:
|
if options.debug:
|
||||||
LOGGING_CONFIG['root']['handlers'].append('debug')
|
LOGGING_CONFIG['root']['handlers'].append('debug')
|
||||||
|
|
Loading…
Reference in a new issue