From c1bc46cb2cd5f0058cbedcc8e45fe890edb9dc1d Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 19 Jul 2018 12:03:40 +0200 Subject: config: Try to create the logs directory before setting up error logs. --- poezio/config.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/poezio/config.py b/poezio/config.py index c8613acb..e82aa190 100644 --- a/poezio/config.py +++ b/poezio/config.py @@ -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') -- cgit v1.2.3