From 1685f5853aa9b6a3959df9773acc952db814a15c Mon Sep 17 00:00:00 2001 From: wanghao Date: Tue, 9 Feb 2016 20:47:12 +0800 Subject: [PATCH] Fix improperly LOG using in Zaqar In zaqar, there are some improperly log using in code tree. Like in some place, should use LOG.exception not LOG.error, repeat log calling, etc. Those could be optimized for better code. Change-Id: I99b830c4db4f2b9449cad713f37474f5ecbce05e Closes-Bug: #1543563 --- zaqar/bootstrap.py | 6 ++++-- zaqar/notification/notifier.py | 3 ++- zaqar/notification/task/mailto.py | 7 +++---- zaqar/notification/task/webhook.py | 4 +++- zaqar/storage/mongodb/utils.py | 11 ++++++----- zaqar/storage/redis/utils.py | 11 ++++++----- zaqar/storage/utils.py | 5 +++-- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/zaqar/bootstrap.py b/zaqar/bootstrap.py index ff8415f12..89d812e88 100644 --- a/zaqar/bootstrap.py +++ b/zaqar/bootstrap.py @@ -28,6 +28,8 @@ from zaqar.storage import utils as storage_utils from zaqar.transport import base from zaqar.transport import validation +from zaqar.i18n import _LE + LOG = log.getLogger(__name__) @@ -123,8 +125,8 @@ class Bootstrap(object): return mgr.driver except RuntimeError as exc: LOG.exception(exc) - LOG.error(u'Failed to load transport driver zaqar.transport.' - u'%(driver)s with args %(args)s', + LOG.error(_LE(u'Failed to load transport driver zaqar.transport.' + u'%(driver)s with args %(args)s'), {'driver': transport_name, 'args': args}) raise errors.InvalidDriver(exc) diff --git a/zaqar/notification/notifier.py b/zaqar/notification/notifier.py index 069c7403d..f1c9e4c6a 100644 --- a/zaqar/notification/notifier.py +++ b/zaqar/notification/notifier.py @@ -19,6 +19,7 @@ import futurist from oslo_log import log as logging from six.moves import urllib_parse +from zaqar.i18n import _LE from zaqar.storage import pooling LOG = logging.getLogger(__name__) @@ -51,4 +52,4 @@ class NotifierDriver(object): self.executor.submit(mgr.driver.execute, sub, messages, conf=data_driver.conf) else: - LOG.error('Failed to get subscription controller.') + LOG.error(_LE('Failed to get subscription controller.')) diff --git a/zaqar/notification/task/mailto.py b/zaqar/notification/task/mailto.py index 99b65f4d4..58eb077f8 100644 --- a/zaqar/notification/task/mailto.py +++ b/zaqar/notification/task/mailto.py @@ -43,8 +43,7 @@ class MailtoTask(object): msg["subject"] = params.get('subject', subject_opt) p.communicate(msg.as_string()) except OSError as err: - LOG.error(_LE('Failed to create process for sendmail, ' - 'because %s') % str(err)) + LOG.exception(_LE('Failed to create process for sendmail, ' + 'because %s.') % str(err)) except Exception as exc: - LOG.exception(_LE('Failed to send email')) - LOG.exception(exc) + LOG.exception(_LE('Failed to send email because %s.') % str(exc)) diff --git a/zaqar/notification/task/webhook.py b/zaqar/notification/task/webhook.py index b2b2dbb59..9f65d1d40 100644 --- a/zaqar/notification/task/webhook.py +++ b/zaqar/notification/task/webhook.py @@ -17,6 +17,8 @@ import json from oslo_log import log as logging import requests +from zaqar.i18n import _LE + LOG = logging.getLogger(__name__) @@ -29,4 +31,4 @@ class WebhookTask(object): data=json.dumps(msg), headers={'Content-Type': 'application/json'}) except Exception as e: - LOG.error(e) + LOG.exception(_LE('webhook task got exception: %s.') % str(e)) diff --git a/zaqar/storage/mongodb/utils.py b/zaqar/storage/mongodb/utils.py index 28392c7f4..b2d711fdf 100644 --- a/zaqar/storage/mongodb/utils.py +++ b/zaqar/storage/mongodb/utils.py @@ -28,7 +28,8 @@ from oslo_log import log as logging from oslo_utils import timeutils from pymongo import errors -from zaqar.i18n import _ +from zaqar.i18n import _LE +from zaqar.i18n import _LW from zaqar.storage import errors as storage_errors @@ -287,14 +288,14 @@ def retries_on_autoreconnect(func): break except errors.AutoReconnect as ex: - LOG.warning(_(u'Caught AutoReconnect, retrying the ' - 'call to {0}').format(func)) + LOG.warning(_LW(u'Caught AutoReconnect, retrying the ' + 'call to {0}').format(func)) last_ex = ex time.sleep(sleep_sec * (2 ** attempt)) else: - LOG.error(_(u'Caught AutoReconnect, maximum attempts ' - 'to {0} exceeded.').format(func)) + LOG.error(_LE(u'Caught AutoReconnect, maximum attempts ' + 'to {0} exceeded.').format(func)) raise last_ex diff --git a/zaqar/storage/redis/utils.py b/zaqar/storage/redis/utils.py index 530ccae44..13c8b3169 100644 --- a/zaqar/storage/redis/utils.py +++ b/zaqar/storage/redis/utils.py @@ -23,7 +23,8 @@ from oslo_utils import encodeutils import redis import six -from zaqar.i18n import _ +from zaqar.i18n import _LE +from zaqar.i18n import _LW from zaqar.storage import errors LOG = logging.getLogger(__name__) @@ -210,13 +211,13 @@ def retries_on_connection_error(func): # MasterNotFoundError. ex = sys.exc_info()[1] - LOG.warning(_(u'Caught ConnectionError, retrying the ' - 'call to {0}').format(func)) + LOG.warning(_LW(u'Caught ConnectionError, retrying the ' + 'call to {0}').format(func)) time.sleep(sleep_sec * (2 ** attempt)) else: - LOG.error(_(u'Caught ConnectionError, maximum attempts ' - 'to {0} exceeded.').format(func)) + LOG.error(_LE(u'Caught ConnectionError, maximum attempts ' + 'to {0} exceeded.').format(func)) raise ex return wrapper diff --git a/zaqar/storage/utils.py b/zaqar/storage/utils.py index d433593cc..29af0836b 100644 --- a/zaqar/storage/utils.py +++ b/zaqar/storage/utils.py @@ -21,6 +21,7 @@ from stevedore import driver from zaqar.common import errors from zaqar.common import utils +from zaqar.i18n import _LE LOG = log.getLogger(__name__) @@ -140,8 +141,8 @@ def load_storage_driver(conf, cache, storage_type=None, return mgr.driver except Exception as exc: - LOG.error('Failed to load "{}" driver for "{}"'.format(driver_type, - storage_type)) + LOG.error(_LE('Failed to load "{}" driver for "{}"').format( + driver_type, storage_type)) LOG.exception(exc) raise errors.InvalidDriver(exc)