From 409108c74f79dba7167c6a5f0ff79fe0553fbe32 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Tue, 20 May 2014 14:50:23 +0200 Subject: [PATCH] replace string format arguments with function parameters There are files containing string format arguments inside logging messages. Using logging function parameters should be preferred. Change-Id: I4a7ce6916aefb2f2d445f0ebd977c824b1c51e24 Partial-Bug: #1321274 --- oslo/messaging/_drivers/amqp.py | 2 +- oslo/messaging/_drivers/amqpdriver.py | 6 +++--- oslo/messaging/_drivers/common.py | 2 +- oslo/messaging/_drivers/impl_qpid.py | 8 ++++---- oslo/messaging/_drivers/impl_rabbit.py | 16 ++++++++-------- oslo/messaging/_drivers/impl_zmq.py | 10 +++++----- oslo/messaging/_drivers/matchmaker_ring.py | 4 ++-- oslo/messaging/notify/_impl_routing.py | 10 ++++------ oslo/messaging/notify/dispatcher.py | 2 +- oslo/messaging/rpc/dispatcher.py | 2 +- tests/test_notify_dispatcher.py | 3 ++- 11 files changed, 32 insertions(+), 33 deletions(-) diff --git a/oslo/messaging/_drivers/amqp.py b/oslo/messaging/_drivers/amqp.py index e0d33b393..fcd077314 100644 --- a/oslo/messaging/_drivers/amqp.py +++ b/oslo/messaging/_drivers/amqp.py @@ -248,4 +248,4 @@ def _add_unique_id(msg): """Add unique_id for checking duplicate messages.""" unique_id = uuid.uuid4().hex msg.update({UNIQUE_ID: unique_id}) - LOG.debug('UNIQUE_ID is %s.' % (unique_id)) + LOG.debug('UNIQUE_ID is %s.', unique_id) diff --git a/oslo/messaging/_drivers/amqpdriver.py b/oslo/messaging/_drivers/amqpdriver.py index 820c3f7a5..b9b7a9473 100644 --- a/oslo/messaging/_drivers/amqpdriver.py +++ b/oslo/messaging/_drivers/amqpdriver.py @@ -137,7 +137,7 @@ class ReplyWaiters(object): LOG.warn('No calling threads waiting for msg_id : %(msg_id)s' ', message : %(data)s', {'msg_id': msg_id, 'data': message_data}) - LOG.warn('_queues: %s' % self._queues) + LOG.warn('_queues: %s', self._queues) else: queue.put(message_data) @@ -150,7 +150,7 @@ class ReplyWaiters(object): self._queues[msg_id] = queue if len(self._queues) > self._wrn_threshold: LOG.warn('Number of call queues is greater than warning ' - 'threshold: %d. There could be a leak.' % + 'threshold: %d. There could be a leak.', self._wrn_threshold) self._wrn_threshold *= 2 @@ -348,7 +348,7 @@ class AMQPDriverBase(base.BaseDriver): if wait_for_reply: msg_id = uuid.uuid4().hex msg.update({'_msg_id': msg_id}) - LOG.debug('MSG_ID is %s' % (msg_id)) + LOG.debug('MSG_ID is %s', msg_id) msg.update({'_reply_q': self._get_reply_q()}) rpc_amqp._add_unique_id(msg) diff --git a/oslo/messaging/_drivers/common.py b/oslo/messaging/_drivers/common.py index af02effd7..45a75f103 100644 --- a/oslo/messaging/_drivers/common.py +++ b/oslo/messaging/_drivers/common.py @@ -88,7 +88,7 @@ class RPCException(Exception): # log the issue and the kwargs LOG.exception(_('Exception in string format operation')) for name, value in six.iteritems(kwargs): - LOG.error("%s: %s" % (name, value)) + LOG.error("%s: %s", name, value) # at least get the core message out if something happened message = self.msg_fmt diff --git a/oslo/messaging/_drivers/impl_qpid.py b/oslo/messaging/_drivers/impl_qpid.py index 0d62192bd..c78fcba22 100644 --- a/oslo/messaging/_drivers/impl_qpid.py +++ b/oslo/messaging/_drivers/impl_qpid.py @@ -607,7 +607,7 @@ class Connection(object): def _connect_error(exc): log_info = {'topic': topic, 'err_str': exc} LOG.error(_("Failed to declare consumer for topic '%(topic)s': " - "%(err_str)s") % log_info) + "%(err_str)s"), log_info) def _declare_consumer(): consumer = consumer_cls(self.conf, self.session, topic, callback) @@ -621,10 +621,10 @@ class Connection(object): def _error_callback(exc): if isinstance(exc, qpid_exceptions.Empty): - LOG.debug('Timed out waiting for RPC response: %s' % exc) + LOG.debug('Timed out waiting for RPC response: %s', exc) raise rpc_common.Timeout() else: - LOG.exception(_('Failed to consume message from queue: %s') % + LOG.exception(_('Failed to consume message from queue: %s'), exc) def _consume(): @@ -645,7 +645,7 @@ class Connection(object): def _connect_error(exc): log_info = {'topic': topic, 'err_str': exc} LOG.exception(_("Failed to publish message to topic " - "'%(topic)s': %(err_str)s") % log_info) + "'%(topic)s': %(err_str)s"), log_info) def _publisher_send(): publisher = cls(self.conf, self.session, topic=topic, **kwargs) diff --git a/oslo/messaging/_drivers/impl_rabbit.py b/oslo/messaging/_drivers/impl_rabbit.py index 3ced930d1..f93060c8d 100644 --- a/oslo/messaging/_drivers/impl_rabbit.py +++ b/oslo/messaging/_drivers/impl_rabbit.py @@ -541,7 +541,7 @@ class Connection(object): be handled by the caller. """ LOG.info(_("Connecting to AMQP server on " - "%(hostname)s:%(port)d") % broker) + "%(hostname)s:%(port)d"), broker) self.connection = kombu.connection.BrokerConnection(**broker) self.connection_errors = self.connection.connection_errors self.channel_errors = self.connection.channel_errors @@ -557,7 +557,7 @@ class Connection(object): self.channel._new_queue('ae.undeliver') for consumer in self.consumers: consumer.reconnect(self.channel) - LOG.info(_('Connected to AMQP server on %(hostname)s:%(port)d') % + LOG.info(_('Connected to AMQP server on %(hostname)s:%(port)d'), broker) def _disconnect(self): @@ -643,11 +643,11 @@ class Connection(object): if 'Socket closed' in six.text_type(e): LOG.error(_('AMQP server %(hostname)s:%(port)d closed' ' the connection. Check login credentials:' - ' %(err_str)s') % log_info) + ' %(err_str)s'), log_info) else: LOG.error(_('AMQP server on %(hostname)s:%(port)d is ' 'unreachable: %(err_str)s. Trying again in ' - '%(sleep_time)d seconds.') % log_info) + '%(sleep_time)d seconds.'), log_info) time.sleep(sleep_time) def ensure(self, error_callback, method, retry=None): @@ -703,7 +703,7 @@ class Connection(object): def _connect_error(exc): log_info = {'topic': topic, 'err_str': exc} LOG.error(_("Failed to declare consumer for topic '%(topic)s': " - "%(err_str)s") % log_info) + "%(err_str)s"), log_info) def _declare_consumer(): consumer = consumer_cls(self.conf, self.channel, topic, callback, @@ -718,10 +718,10 @@ class Connection(object): def _error_callback(exc): if isinstance(exc, socket.timeout): - LOG.debug('Timed out waiting for RPC response: %s' % exc) + LOG.debug('Timed out waiting for RPC response: %s', exc) raise rpc_common.Timeout() else: - LOG.exception(_('Failed to consume message from queue: %s') % + LOG.exception(_('Failed to consume message from queue: %s'), exc) self.do_consume = True @@ -747,7 +747,7 @@ class Connection(object): def _error_callback(exc): log_info = {'topic': topic, 'err_str': exc} LOG.exception(_("Failed to publish message to topic " - "'%(topic)s': %(err_str)s") % log_info) + "'%(topic)s': %(err_str)s"), log_info) def _publish(): publisher = cls(self.conf, self.channel, topic=topic, **kwargs) diff --git a/oslo/messaging/_drivers/impl_zmq.py b/oslo/messaging/_drivers/impl_zmq.py index 542731966..804fed037 100644 --- a/oslo/messaging/_drivers/impl_zmq.py +++ b/oslo/messaging/_drivers/impl_zmq.py @@ -286,7 +286,7 @@ class InternalContext(object): # ignore these since they are just from shutdowns pass except rpc_common.ClientException as e: - LOG.debug("Expected exception during message handling (%s)" % + LOG.debug("Expected exception during message handling (%s)", e._exc_info[1]) return {'exc': rpc_common.serialize_remote_exception(e._exc_info, @@ -488,7 +488,7 @@ class ZmqProxy(ZmqBaseReactor): self.topic_proxy[topic].put_nowait(data) except eventlet.queue.Full: LOG.error(_("Local per-topic backlog buffer full for topic " - "%(topic)s. Dropping message.") % {'topic': topic}) + "%s. Dropping message."), topic) def consume_in_thread(self): """Runs the ZmqProxy service.""" @@ -504,7 +504,7 @@ class ZmqProxy(ZmqBaseReactor): if not os.path.isdir(ipc_dir): with excutils.save_and_reraise_exception(): LOG.error(_("Required IPC directory does not exist at" - " %s") % (ipc_dir, )) + " %s"), ipc_dir) try: self.register(consumption_proxy, consume_in, @@ -513,7 +513,7 @@ class ZmqProxy(ZmqBaseReactor): if os.access(ipc_dir, os.X_OK): with excutils.save_and_reraise_exception(): LOG.error(_("Permission denied to IPC directory at" - " %s") % (ipc_dir, )) + " %s"), ipc_dir) with excutils.save_and_reraise_exception(): LOG.error(_("Could not create ZeroMQ receiver daemon. " "Socket may already be in use.")) @@ -728,7 +728,7 @@ def _multi_send(method, context, topic, msg, timeout=None, Dispatches to the matchmaker and sends message to all relevant hosts. """ conf = CONF - LOG.debug("%(msg)s" % {'msg': ' '.join(map(pformat, (topic, msg)))}) + LOG.debug(' '.join(map(pformat, (topic, msg)))) queues = _get_matchmaker().queues(topic) LOG.debug("Sending message(s) to: %s", queues) diff --git a/oslo/messaging/_drivers/matchmaker_ring.py b/oslo/messaging/_drivers/matchmaker_ring.py index 3bcae0235..e3c02b059 100644 --- a/oslo/messaging/_drivers/matchmaker_ring.py +++ b/oslo/messaging/_drivers/matchmaker_ring.py @@ -74,7 +74,7 @@ class RoundRobinRingExchange(RingExchange): if not self._ring_has(key): LOG.warn( _("No key defining hosts for topic '%s', " - "see ringfile") % (key, ) + "see ringfile"), key ) return [] host = next(self.ring0[key]) @@ -92,7 +92,7 @@ class FanoutRingExchange(RingExchange): if not self._ring_has(nkey): LOG.warn( _("No key defining hosts for topic '%s', " - "see ringfile") % (nkey, ) + "see ringfile"), nkey ) return [] return map(lambda x: (key + '.' + x, x), self.ring[nkey]) diff --git a/oslo/messaging/notify/_impl_routing.py b/oslo/messaging/notify/_impl_routing.py index e7d9db58a..efb12564d 100644 --- a/oslo/messaging/notify/_impl_routing.py +++ b/oslo/messaging/notify/_impl_routing.py @@ -70,17 +70,15 @@ class RoutingDriver(notifier._Driver): for group in self.routing_groups.values(): self.used_drivers.update(group.keys()) - LOG.debug('loading notifiers from %(namespace)s' % - {'namespace': self.NOTIFIER_PLUGIN_NAMESPACE}) + LOG.debug('loading notifiers from %s', self.NOTIFIER_PLUGIN_NAMESPACE) self.plugin_manager = dispatch.DispatchExtensionManager( namespace=self.NOTIFIER_PLUGIN_NAMESPACE, check_func=self._should_load_plugin, invoke_on_load=True, invoke_args=None) if not list(self.plugin_manager): - LOG.warning(_("Failed to load any notifiers " - "for %(namespace)s") % - {'namespace': self.NOTIFIER_PLUGIN_NAMESPACE}) + LOG.warning(_("Failed to load any notifiers for %s"), + self.NOTIFIER_PLUGIN_NAMESPACE) def _get_drivers_for_message(self, group, event_type, priority): """Which drivers should be called for this event_type @@ -116,7 +114,7 @@ class RoutingDriver(notifier._Driver): """Emit the notification. """ # accepted_drivers is passed in as a result of the map() function - LOG.info(_("Routing '%(event)s' notification to '%(driver)s' driver") % + LOG.info(_("Routing '%(event)s' notification to '%(driver)s' driver"), {'event': message.get('event_type'), 'driver': ext.name}) ext.obj.notify(context, message, priority, retry) diff --git a/oslo/messaging/notify/dispatcher.py b/oslo/messaging/notify/dispatcher.py index f9186a0be..098e6b18c 100644 --- a/oslo/messaging/notify/dispatcher.py +++ b/oslo/messaging/notify/dispatcher.py @@ -108,7 +108,7 @@ class NotificationDispatcher(object): } priority = message.get('priority', '').lower() if priority not in PRIORITIES: - LOG.warning('Unknown priority "%s"' % priority) + LOG.warning('Unknown priority "%s"', priority) return payload = self.serializer.deserialize_entity(ctxt, diff --git a/oslo/messaging/rpc/dispatcher.py b/oslo/messaging/rpc/dispatcher.py index 328ea44cf..7dce7659a 100644 --- a/oslo/messaging/rpc/dispatcher.py +++ b/oslo/messaging/rpc/dispatcher.py @@ -133,7 +133,7 @@ class RPCDispatcher(object): incoming.reply(self._dispatch(incoming.ctxt, incoming.message)) except ExpectedException as e: - LOG.debug(u'Expected exception during message handling (%s)' % + LOG.debug(u'Expected exception during message handling (%s)', e.exc_info[1]) incoming.reply(failure=e.exc_info, log_failure=False) except Exception as e: diff --git a/tests/test_notify_dispatcher.py b/tests/test_notify_dispatcher.py index 5006cb807..34252b53a 100644 --- a/tests/test_notify_dispatcher.py +++ b/tests/test_notify_dispatcher.py @@ -145,4 +145,5 @@ class TestDispatcher(test_utils.BaseTestCase): [mock.Mock()], [mock.Mock()], None, allow_requeue=True) with dispatcher(mock.Mock(ctxt={}, message=msg)) as callback: callback() - mylog.warning.assert_called_once_with('Unknown priority "what???"') + mylog.warning.assert_called_once_with('Unknown priority "%s"', + 'what???')