From a65fe97f7078ae94e2974a1afddb724028274419 Mon Sep 17 00:00:00 2001 From: Lachlan Plant Date: Mon, 22 Oct 2018 10:48:44 -0500 Subject: [PATCH] Change nova-api-proxy logging backend to oslo_log This changes the logging backend to oslo_log, from native python logging This is required for the containerization of the nova-api-proxy Change-Id: I0fb847c2d6b3178c15e78d063eb7c356a6c61979 Story: 2004007 Task: 27607 Depends-On: https://review.openstack.org/612427 Signed-off-by: Lachlan Plant --- .../nova_api_proxy/api_proxy.py | 6 +- .../nova_api_proxy/apps/acceptor.py | 5 +- .../nova_api_proxy/apps/dispatcher.py | 4 +- .../nova_api_proxy/apps/proxy.py | 4 +- .../nova_api_proxy/common/config.py | 4 +- .../nova_api_proxy/common/histogram.py | 4 +- .../nova_api_proxy/common/log.py | 64 ------------------- .../nova_api_proxy/common/service.py | 7 +- 8 files changed, 17 insertions(+), 81 deletions(-) delete mode 100644 nova-api-proxy/nova-api-proxy/nova_api_proxy/common/log.py diff --git a/nova-api-proxy/nova-api-proxy/nova_api_proxy/api_proxy.py b/nova-api-proxy/nova-api-proxy/nova_api_proxy/api_proxy.py index b0b4b57c..d9389066 100644 --- a/nova-api-proxy/nova-api-proxy/nova_api_proxy/api_proxy.py +++ b/nova-api-proxy/nova-api-proxy/nova_api_proxy/api_proxy.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -11,9 +11,9 @@ import signal import eventlet from oslo_config import cfg +from oslo_log import log as logging from nova_api_proxy.common import config from nova_api_proxy.common.service import Server -from nova_api_proxy.common import log as logging from nova_api_proxy.common import histogram LOG = logging.getLogger(__name__) @@ -68,7 +68,9 @@ def main(): signal.signal(signal.SIGUSR1, process_signal_handler) signal.signal(signal.SIGUSR2, process_signal_handler) + logging.register_options(cfg.CONF) config.parse_args(sys.argv) + logging.setup(cfg.CONF, 'nova-api-proxy') should_use_ssl = CONF.use_ssl LOG.debug("Load paste apps") diff --git a/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/acceptor.py b/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/acceptor.py index 3b8fc24d..8a83cf64 100644 --- a/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/acceptor.py +++ b/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/acceptor.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -10,7 +10,7 @@ import webob.exc from paste.request import construct_url from oslo_config import cfg -from nova_api_proxy.common import log as logging +from oslo_log import log as logging from nova_api_proxy.common import utils from nova_api_proxy.common.service import Middleware from nova_api_proxy.common.service import Request @@ -37,7 +37,6 @@ proxy_opts = [ CONF = cfg.CONF CONF.register_opts(proxy_opts) -CONF.import_opt('debug', 'nova_api_proxy.common.log') class APIController(Middleware): diff --git a/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/dispatcher.py b/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/dispatcher.py index 8fb437a2..99d112b0 100644 --- a/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/dispatcher.py +++ b/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/dispatcher.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -9,8 +9,8 @@ import webob.dec import webob.exc from oslo_config import cfg +from oslo_log import log as proxy_log from nova_api_proxy.common import utils -from nova_api_proxy.common import log as proxy_log from nova_api_proxy.common.service import Middleware LOG = proxy_log.getLogger(__name__) diff --git a/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py b/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py index bb1ec3fc..685f64a4 100644 --- a/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py +++ b/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py @@ -7,7 +7,7 @@ # (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -16,7 +16,7 @@ import httplib import urllib from paste.proxy import TransparentProxy from paste.proxy import parse_headers -from nova_api_proxy.common import log as logging +from oslo_log import log as logging from nova_api_proxy.common.service import Application from nova_api_proxy.common.timestamp import get_monotonic_timestamp_in_ms from nova_api_proxy.common import histogram diff --git a/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/config.py b/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/config.py index e348990b..97a9d962 100644 --- a/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/config.py +++ b/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/config.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -8,7 +8,7 @@ import os from oslo_config import cfg from paste import deploy -from nova_api_proxy.common import log as logging +from oslo_log import log as logging LOG = logging.getLogger(__name__) diff --git a/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/histogram.py b/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/histogram.py index f4ea7984..f0a258a7 100644 --- a/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/histogram.py +++ b/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/histogram.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -7,7 +7,7 @@ import math import array import datetime -from nova_api_proxy.common import log as logging +from oslo_log import log as logging LOG = logging.getLogger(__name__) diff --git a/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/log.py b/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/log.py deleted file mode 100644 index 4b718cff..00000000 --- a/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/log.py +++ /dev/null @@ -1,64 +0,0 @@ -# -# Copyright (c) 2015-2016 Wind River Systems, Inc. -# -# SPDX-License-Identifier: Apache-2.0 -# - -import os -import logging -import inspect -from oslo_config import cfg -from logging.handlers import SysLogHandler - -conf_opts = [ - cfg.BoolOpt('debug', - default=False, - help='Print debugging output (set logging level to ' - 'DEBUG instead of default INFO level).'), -] - -CONF = cfg.CONF -CONF.register_opts(conf_opts) - - -def _get_binary_name(): - return os.path.basename(inspect.stack()[-1][1]) - - -class ProxySysLogHandler(SysLogHandler): - def __init__(self, app, *args, **kwargs): - self.binary_name = _get_binary_name() - self.app = app - SysLogHandler.__init__(self, *args, **kwargs) - - def format(self, record): - msg = logging.handlers.SysLogHandler.format(self, record) - return self.binary_name + '(' + self.app + ')' + ': ' + msg - - -_loggers = {} - - -def _set_log_level(logger, debug): - if debug: - logger.setLevel(logging.DEBUG) - else: - logger.setLevel(logging.INFO) - - -def toggle_debug_log(debug): - for k in _loggers.keys(): - _set_log_level(_loggers[k], debug) - - -def getLogger(name='unknown'): - if name not in _loggers: - _loggers[name] = logging.getLogger(name) - - _set_log_level(_loggers[name], CONF.debug) - - syslog = ProxySysLogHandler(name, address='/dev/log', - facility=SysLogHandler.LOG_LOCAL5) - _loggers[name].addHandler(syslog) - - return _loggers[name] diff --git a/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/service.py b/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/service.py index 1aff809d..e14c64a0 100644 --- a/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/service.py +++ b/nova-api-proxy/nova-api-proxy/nova_api_proxy/common/service.py @@ -11,12 +11,11 @@ # License for the specific language governing permissions and limitations # under the License. # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # import errno import os -import logging import eventlet import webob.dec import webob.exc @@ -25,12 +24,12 @@ import eventlet.wsgi from eventlet.green import socket from eventlet.green import ssl from oslo_config import cfg +from oslo_log import log as logging -from nova_api_proxy.common import log as proxy_log from nova_api_proxy.common.exception import ProxyException -LOG = proxy_log.getLogger(__name__) +LOG = logging.getLogger(__name__) URL_LENGTH_LIMIT = 50000