Merge "Allow loading logging config from yaml" into feature/zuulv3

This commit is contained in:
Jenkins
2017-06-07 17:18:18 +00:00
committed by Gerrit Code Review
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'