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 = 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 can’t really log any error here, because logging isn’t 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')
|
||||
|
|
Loading…
Reference in a new issue