From 2b346e3c01c094922e3d96411370c8394f5e38d4 Mon Sep 17 00:00:00 2001 From: James Lu Date: Wed, 12 Jul 2017 22:40:07 -0700 Subject: [PATCH] conf: use Python logging when avaiable when the config file fails to load --- conf.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/conf.py b/conf.py index cc71bca..de74cfe 100644 --- a/conf.py +++ b/conf.py @@ -121,10 +121,15 @@ def loadConf(filename, errors_fatal=True, logger=None): conf = yaml.load(f) conf = validateConf(conf, logger=logger) except Exception as e: - print('ERROR: Failed to load config from %r: %s: %s' % (filename, type(e).__name__, e), file=sys.stderr) + e = 'Failed to load config from %r: %s: %s' % (filename, type(e).__name__, e) if errors_fatal: sys.exit(1) + elif logger: # Prefer using the Python logger when available + logger.exception(e) + else: # Otherwise, fall back to a print() call. + print('ERROR: %s' % e, file=sys.stderr) + raise else: return conf