]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix import log_handler error with publish_errors set
authorChang Bo Guo <guochbo@cn.ibm.com>
Wed, 6 Nov 2013 06:56:36 +0000 (22:56 -0800)
committerChang Bo Guo <guochbo@cn.ibm.com>
Fri, 17 Jan 2014 02:14:05 +0000 (18:14 -0800)
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 [new file with mode: 0644]
openstack-common.conf

diff --git a/cinder/openstack/common/log_handler.py b/cinder/openstack/common/log_handler.py
new file mode 100644 (file)
index 0000000..ebeb9ab
--- /dev/null
@@ -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))
index 555cd1efecca5eef484576b6554f8170ee32e2de..e93b286d405e8b814de9ac84d06683cdc8a7432e 100644 (file)
@@ -16,6 +16,7 @@ module=jsonutils
 module=local
 module=lockutils
 module=log
+module=log_handler
 module=network_utils
 module=notifier
 module=periodic_task