Allow loading logging config from yaml

The newer dictConfig logging configuration allows a much more flexible
configuration and should be used in preference to the file config. For
backwards compatibility if the logging configuration has a yaml
extension then load it, otherwise fall back to the file config.

Change-Id: Ia29e294144fa057ded7b72e4475265766f855494
This commit is contained in:
Jamie Lennox 2017-02-17 17:21:07 +11:00
parent 399503f3ac
commit 7f10787e9a
2 changed files with 18 additions and 4 deletions

View File

@ -61,6 +61,13 @@ configurations that contain sensitive data, this is currently not used, but
may be in the future.
There is an optional logging configuration file, specified with the ``-l``
option. The logging configuration file is in the standard python logging
`configuration file format
<http://docs.python.org/2/library/logging.config.html#configuration-file-format>`_.
option. The logging configuration file can accept either:
* the traditional ini python logging `configuration file format
<https://docs.python.org/2/library/logging.config.html#configuration-file-format>`_.
* a `.yml` or `.yaml` suffixed file that will be parsed and loaded as the newer
`dictConfig format
<https://docs.python.org/2/library/logging.config.html#configuration-dictionary-schema>`_.
The Nodepool configuration file is described in :ref:`configuration`.

View File

@ -26,6 +26,8 @@ import sys
import threading
import traceback
import yaml
from nodepool.version import version_info as npd_version_info
@ -105,7 +107,12 @@ class NodepoolApp(object):
m = "Unable to read logging config file at %s" % fp
raise Exception(m)
logging.config.fileConfig(fp)
if os.path.splitext(fp)[1] in ('.yml', '.yaml'):
with open(fp, 'r') as f:
logging.config.dictConfig(yaml.safe_load(f))
else:
logging.config.fileConfig(fp)
else:
m = '%(asctime)s %(levelname)s %(name)s: %(message)s'