diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-07-19 12:03:40 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-07-19 12:03:40 +0200 |
commit | c1bc46cb2cd5f0058cbedcc8e45fe890edb9dc1d (patch) | |
tree | a5acee5b059ed356a1016cbad501c3dd519106b7 | |
parent | 31ec0564e71e2c3a2b7538d10c7abd4c86853fc0 (diff) | |
download | poezio-c1bc46cb2cd5f0058cbedcc8e45fe890edb9dc1d.tar.gz poezio-c1bc46cb2cd5f0058cbedcc8e45fe890edb9dc1d.tar.bz2 poezio-c1bc46cb2cd5f0058cbedcc8e45fe890edb9dc1d.tar.xz poezio-c1bc46cb2cd5f0058cbedcc8e45fe890edb9dc1d.zip |
config: Try to create the logs directory before setting up error logs.
-rw-r--r-- | poezio/config.py | 22 |
1 files 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') |