summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-07-19 12:03:40 +0200
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-07-19 12:03:40 +0200
commitc1bc46cb2cd5f0058cbedcc8e45fe890edb9dc1d (patch)
treea5acee5b059ed356a1016cbad501c3dd519106b7
parent31ec0564e71e2c3a2b7538d10c7abd4c86853fc0 (diff)
downloadpoezio-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.py22
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')