From 8c56f24291504acaef93b094c73f50126a18dd7e Mon Sep 17 00:00:00 2001 From: Elena Ezhova Date: Fri, 5 Jun 2015 14:19:44 +0300 Subject: [PATCH] Make logging option values configurable It is not always desirable to log full set of conf at service start. This change adds new option "log_options" that allows to enable or disable logging values of all registered options. Also moved list_opts function for service submodule to service.py as service and eventlet_backdoor opts have to be grouped together and changed the entrypoint accordingly. Change-Id: I2a97ebf736fd361e6f1d05796d5077bc9627ff85 Closes-Bug: #1461250 --- oslo_service/_options.py | 7 +++++++ oslo_service/eventlet_backdoor.py | 7 ------- oslo_service/service.py | 20 ++++++++++++++++---- setup.cfg | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/oslo_service/_options.py b/oslo_service/_options.py index 92970904..3db55026 100644 --- a/oslo_service/_options.py +++ b/oslo_service/_options.py @@ -34,6 +34,13 @@ periodic_opts = [ 'Should we run them here?'), ] +service_opts = [ + cfg.BoolOpt('log_options', + default=True, + help='Enables or disables logging values of all registered ' + 'options when starting a service (at DEBUG level).'), +] + ssl_opts = [ cfg.StrOpt('ca_file', help="CA certificate file to use to verify " diff --git a/oslo_service/eventlet_backdoor.py b/oslo_service/eventlet_backdoor.py index 46a73430..eed0bbe8 100644 --- a/oslo_service/eventlet_backdoor.py +++ b/oslo_service/eventlet_backdoor.py @@ -16,7 +16,6 @@ from __future__ import print_function -import copy import errno import gc import logging @@ -39,12 +38,6 @@ CONF.register_opts(_options.eventlet_backdoor_opts) LOG = logging.getLogger(__name__) -def list_opts(): - """Entry point for oslo-config-generator. - """ - return [(None, copy.deepcopy(_options.eventlet_backdoor_opts))] - - class EventletBackdoorConfigValueError(Exception): def __init__(self, port_range, help_msg, ex): msg = ('Invalid backdoor_port configuration %(range)s: %(ex)s. ' diff --git a/oslo_service/service.py b/oslo_service/service.py index 30881278..21a58000 100644 --- a/oslo_service/service.py +++ b/oslo_service/service.py @@ -29,6 +29,7 @@ one instance of ServiceLauncher and ProcessLauncher classes per process. """ import abc +import copy import errno import io import logging @@ -45,14 +46,23 @@ from oslo_config import cfg from oslo_service import eventlet_backdoor from oslo_service._i18n import _LE, _LI, _LW +from oslo_service import _options from oslo_service import systemd from oslo_service import threadgroup CONF = cfg.CONF +CONF.register_opts(_options.service_opts) + LOG = logging.getLogger(__name__) +def list_opts(): + """Entry point for oslo-config-generator.""" + return [(None, copy.deepcopy(_options.eventlet_backdoor_opts + + _options.service_opts))] + + def _sighup_supported(): return hasattr(signal, 'SIGHUP') @@ -191,8 +201,9 @@ class ServiceLauncher(Launcher): status = None signo = 0 - LOG.debug('Full set of CONF:') - CONF.log_opt_values(LOG, logging.DEBUG) + if CONF.log_options: + LOG.debug('Full set of CONF:') + CONF.log_opt_values(LOG, logging.DEBUG) try: if ready_callback: @@ -410,8 +421,9 @@ class ProcessLauncher(object): """Loop waiting on children to die and respawning as necessary.""" systemd.notify_once() - LOG.debug('Full set of CONF:') - CONF.log_opt_values(LOG, logging.DEBUG) + if CONF.log_options: + LOG.debug('Full set of CONF:') + CONF.log_opt_values(LOG, logging.DEBUG) try: while True: diff --git a/setup.cfg b/setup.cfg index 564ed76e..3b04cd86 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,7 +30,7 @@ warnerrors = true [entry_points] oslo.config.opts = oslo.service.periodic_task = oslo_service.periodic_task:list_opts - oslo.service.service = oslo_service.eventlet_backdoor:list_opts + oslo.service.service = oslo_service.service:list_opts oslo.service.sslutils = oslo_service.sslutils:list_opts [build_sphinx]