mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
conf: use Python logging when avaiable when the config file fails to load
This commit is contained in:
parent
db778debb8
commit
2b346e3c01
7
conf.py
7
conf.py
@ -121,10 +121,15 @@ def loadConf(filename, errors_fatal=True, logger=None):
|
|||||||
conf = yaml.load(f)
|
conf = yaml.load(f)
|
||||||
conf = validateConf(conf, logger=logger)
|
conf = validateConf(conf, logger=logger)
|
||||||
except Exception as e:
|
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:
|
if errors_fatal:
|
||||||
sys.exit(1)
|
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
|
raise
|
||||||
else:
|
else:
|
||||||
return conf
|
return conf
|
||||||
|
Loading…
Reference in New Issue
Block a user