From f29f812bc64726b01a50590894d6d430c5f3d30d Mon Sep 17 00:00:00 2001 From: Chang Bo Guo Date: Tue, 5 Nov 2013 22:56:36 -0800 Subject: [PATCH] Fix import log_handler error with publish_errors set Sync latest module log_handler from Oslo. Commit Id is 2843a92a0e4007f50d5ad63d51fe574e1ba5e280 This handler sends the error to configured notifier. The notifier could be any kind (log, RPC, no_op, None). Note: when using publish_errors you also need to set the notification_driver option too. Closes-bug: #1240349 Change-Id: I4f759b049b8f34904ba11382a2e8fc1578677a8f --- cinder/openstack/common/log_handler.py | 29 ++++++++++++++++++++++++++ openstack-common.conf | 1 + 2 files changed, 30 insertions(+) create mode 100644 cinder/openstack/common/log_handler.py diff --git a/cinder/openstack/common/log_handler.py b/cinder/openstack/common/log_handler.py new file mode 100644 index 000000000..ebeb9ab73 --- /dev/null +++ b/cinder/openstack/common/log_handler.py @@ -0,0 +1,29 @@ +# Copyright 2013 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +import logging + +from oslo.config import cfg + +from cinder.openstack.common import notifier + + +class PublishErrorsHandler(logging.Handler): + def emit(self, record): + if ('cinder.openstack.common.notifier.log_notifier' in + cfg.CONF.notification_driver): + return + notifier.api.notify(None, 'error.publisher', + 'error_notification', + notifier.api.ERROR, + dict(error=record.msg)) diff --git a/openstack-common.conf b/openstack-common.conf index 555cd1efe..e93b286d4 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -16,6 +16,7 @@ module=jsonutils module=local module=lockutils module=log +module=log_handler module=network_utils module=notifier module=periodic_task -- 2.45.2