Browse Source

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
Christian Berendt 4 years ago
parent
commit
409108c74f

+ 1
- 1
oslo/messaging/_drivers/amqp.py View File

@@ -248,4 +248,4 @@ def _add_unique_id(msg):
248 248
     """Add unique_id for checking duplicate messages."""
249 249
     unique_id = uuid.uuid4().hex
250 250
     msg.update({UNIQUE_ID: unique_id})
251
-    LOG.debug('UNIQUE_ID is %s.' % (unique_id))
251
+    LOG.debug('UNIQUE_ID is %s.', unique_id)

+ 3
- 3
oslo/messaging/_drivers/amqpdriver.py View File

@@ -137,7 +137,7 @@ class ReplyWaiters(object):
137 137
             LOG.warn('No calling threads waiting for msg_id : %(msg_id)s'
138 138
                      ', message : %(data)s', {'msg_id': msg_id,
139 139
                                               'data': message_data})
140
-            LOG.warn('_queues: %s' % self._queues)
140
+            LOG.warn('_queues: %s', self._queues)
141 141
         else:
142 142
             queue.put(message_data)
143 143
 
@@ -150,7 +150,7 @@ class ReplyWaiters(object):
150 150
         self._queues[msg_id] = queue
151 151
         if len(self._queues) > self._wrn_threshold:
152 152
             LOG.warn('Number of call queues is greater than warning '
153
-                     'threshold: %d. There could be a leak.' %
153
+                     'threshold: %d. There could be a leak.',
154 154
                      self._wrn_threshold)
155 155
             self._wrn_threshold *= 2
156 156
 
@@ -348,7 +348,7 @@ class AMQPDriverBase(base.BaseDriver):
348 348
         if wait_for_reply:
349 349
             msg_id = uuid.uuid4().hex
350 350
             msg.update({'_msg_id': msg_id})
351
-            LOG.debug('MSG_ID is %s' % (msg_id))
351
+            LOG.debug('MSG_ID is %s', msg_id)
352 352
             msg.update({'_reply_q': self._get_reply_q()})
353 353
 
354 354
         rpc_amqp._add_unique_id(msg)

+ 1
- 1
oslo/messaging/_drivers/common.py View File

@@ -88,7 +88,7 @@ class RPCException(Exception):
88 88
                 # log the issue and the kwargs
89 89
                 LOG.exception(_('Exception in string format operation'))
90 90
                 for name, value in six.iteritems(kwargs):
91
-                    LOG.error("%s: %s" % (name, value))
91
+                    LOG.error("%s: %s", name, value)
92 92
                 # at least get the core message out if something happened
93 93
                 message = self.msg_fmt
94 94
 

+ 4
- 4
oslo/messaging/_drivers/impl_qpid.py View File

@@ -607,7 +607,7 @@ class Connection(object):
607 607
         def _connect_error(exc):
608 608
             log_info = {'topic': topic, 'err_str': exc}
609 609
             LOG.error(_("Failed to declare consumer for topic '%(topic)s': "
610
-                      "%(err_str)s") % log_info)
610
+                        "%(err_str)s"), log_info)
611 611
 
612 612
         def _declare_consumer():
613 613
             consumer = consumer_cls(self.conf, self.session, topic, callback)
@@ -621,10 +621,10 @@ class Connection(object):
621 621
 
622 622
         def _error_callback(exc):
623 623
             if isinstance(exc, qpid_exceptions.Empty):
624
-                LOG.debug('Timed out waiting for RPC response: %s' % exc)
624
+                LOG.debug('Timed out waiting for RPC response: %s', exc)
625 625
                 raise rpc_common.Timeout()
626 626
             else:
627
-                LOG.exception(_('Failed to consume message from queue: %s') %
627
+                LOG.exception(_('Failed to consume message from queue: %s'),
628 628
                               exc)
629 629
 
630 630
         def _consume():
@@ -645,7 +645,7 @@ class Connection(object):
645 645
         def _connect_error(exc):
646 646
             log_info = {'topic': topic, 'err_str': exc}
647 647
             LOG.exception(_("Failed to publish message to topic "
648
-                          "'%(topic)s': %(err_str)s") % log_info)
648
+                          "'%(topic)s': %(err_str)s"), log_info)
649 649
 
650 650
         def _publisher_send():
651 651
             publisher = cls(self.conf, self.session, topic=topic, **kwargs)

+ 8
- 8
oslo/messaging/_drivers/impl_rabbit.py View File

@@ -541,7 +541,7 @@ class Connection(object):
541 541
         be handled by the caller.
542 542
         """
543 543
         LOG.info(_("Connecting to AMQP server on "
544
-                   "%(hostname)s:%(port)d") % broker)
544
+                   "%(hostname)s:%(port)d"), broker)
545 545
         self.connection = kombu.connection.BrokerConnection(**broker)
546 546
         self.connection_errors = self.connection.connection_errors
547 547
         self.channel_errors = self.connection.channel_errors
@@ -557,7 +557,7 @@ class Connection(object):
557 557
             self.channel._new_queue('ae.undeliver')
558 558
         for consumer in self.consumers:
559 559
             consumer.reconnect(self.channel)
560
-        LOG.info(_('Connected to AMQP server on %(hostname)s:%(port)d') %
560
+        LOG.info(_('Connected to AMQP server on %(hostname)s:%(port)d'),
561 561
                  broker)
562 562
 
563 563
     def _disconnect(self):
@@ -643,11 +643,11 @@ class Connection(object):
643 643
                 if 'Socket closed' in six.text_type(e):
644 644
                     LOG.error(_('AMQP server %(hostname)s:%(port)d closed'
645 645
                                 ' the connection. Check login credentials:'
646
-                                ' %(err_str)s') % log_info)
646
+                                ' %(err_str)s'), log_info)
647 647
                 else:
648 648
                     LOG.error(_('AMQP server on %(hostname)s:%(port)d is '
649 649
                                 'unreachable: %(err_str)s. Trying again in '
650
-                                '%(sleep_time)d seconds.') % log_info)
650
+                                '%(sleep_time)d seconds.'), log_info)
651 651
                 time.sleep(sleep_time)
652 652
 
653 653
     def ensure(self, error_callback, method, retry=None):
@@ -703,7 +703,7 @@ class Connection(object):
703 703
         def _connect_error(exc):
704 704
             log_info = {'topic': topic, 'err_str': exc}
705 705
             LOG.error(_("Failed to declare consumer for topic '%(topic)s': "
706
-                      "%(err_str)s") % log_info)
706
+                      "%(err_str)s"), log_info)
707 707
 
708 708
         def _declare_consumer():
709 709
             consumer = consumer_cls(self.conf, self.channel, topic, callback,
@@ -718,10 +718,10 @@ class Connection(object):
718 718
 
719 719
         def _error_callback(exc):
720 720
             if isinstance(exc, socket.timeout):
721
-                LOG.debug('Timed out waiting for RPC response: %s' % exc)
721
+                LOG.debug('Timed out waiting for RPC response: %s', exc)
722 722
                 raise rpc_common.Timeout()
723 723
             else:
724
-                LOG.exception(_('Failed to consume message from queue: %s') %
724
+                LOG.exception(_('Failed to consume message from queue: %s'),
725 725
                               exc)
726 726
                 self.do_consume = True
727 727
 
@@ -747,7 +747,7 @@ class Connection(object):
747 747
         def _error_callback(exc):
748 748
             log_info = {'topic': topic, 'err_str': exc}
749 749
             LOG.exception(_("Failed to publish message to topic "
750
-                          "'%(topic)s': %(err_str)s") % log_info)
750
+                          "'%(topic)s': %(err_str)s"), log_info)
751 751
 
752 752
         def _publish():
753 753
             publisher = cls(self.conf, self.channel, topic=topic, **kwargs)

+ 5
- 5
oslo/messaging/_drivers/impl_zmq.py View File

@@ -286,7 +286,7 @@ class InternalContext(object):
286 286
             # ignore these since they are just from shutdowns
287 287
             pass
288 288
         except rpc_common.ClientException as e:
289
-            LOG.debug("Expected exception during message handling (%s)" %
289
+            LOG.debug("Expected exception during message handling (%s)",
290 290
                       e._exc_info[1])
291 291
             return {'exc':
292 292
                     rpc_common.serialize_remote_exception(e._exc_info,
@@ -488,7 +488,7 @@ class ZmqProxy(ZmqBaseReactor):
488 488
             self.topic_proxy[topic].put_nowait(data)
489 489
         except eventlet.queue.Full:
490 490
             LOG.error(_("Local per-topic backlog buffer full for topic "
491
-                        "%(topic)s. Dropping message.") % {'topic': topic})
491
+                        "%s. Dropping message."), topic)
492 492
 
493 493
     def consume_in_thread(self):
494 494
         """Runs the ZmqProxy service."""
@@ -504,7 +504,7 @@ class ZmqProxy(ZmqBaseReactor):
504 504
             if not os.path.isdir(ipc_dir):
505 505
                 with excutils.save_and_reraise_exception():
506 506
                     LOG.error(_("Required IPC directory does not exist at"
507
-                                " %s") % (ipc_dir, ))
507
+                                " %s"), ipc_dir)
508 508
         try:
509 509
             self.register(consumption_proxy,
510 510
                           consume_in,
@@ -513,7 +513,7 @@ class ZmqProxy(ZmqBaseReactor):
513 513
             if os.access(ipc_dir, os.X_OK):
514 514
                 with excutils.save_and_reraise_exception():
515 515
                     LOG.error(_("Permission denied to IPC directory at"
516
-                                " %s") % (ipc_dir, ))
516
+                                " %s"), ipc_dir)
517 517
             with excutils.save_and_reraise_exception():
518 518
                 LOG.error(_("Could not create ZeroMQ receiver daemon. "
519 519
                             "Socket may already be in use."))
@@ -728,7 +728,7 @@ def _multi_send(method, context, topic, msg, timeout=None,
728 728
     Dispatches to the matchmaker and sends message to all relevant hosts.
729 729
     """
730 730
     conf = CONF
731
-    LOG.debug("%(msg)s" % {'msg': ' '.join(map(pformat, (topic, msg)))})
731
+    LOG.debug(' '.join(map(pformat, (topic, msg))))
732 732
 
733 733
     queues = _get_matchmaker().queues(topic)
734 734
     LOG.debug("Sending message(s) to: %s", queues)

+ 2
- 2
oslo/messaging/_drivers/matchmaker_ring.py View File

@@ -74,7 +74,7 @@ class RoundRobinRingExchange(RingExchange):
74 74
         if not self._ring_has(key):
75 75
             LOG.warn(
76 76
                 _("No key defining hosts for topic '%s', "
77
-                  "see ringfile") % (key, )
77
+                  "see ringfile"), key
78 78
             )
79 79
             return []
80 80
         host = next(self.ring0[key])
@@ -92,7 +92,7 @@ class FanoutRingExchange(RingExchange):
92 92
         if not self._ring_has(nkey):
93 93
             LOG.warn(
94 94
                 _("No key defining hosts for topic '%s', "
95
-                  "see ringfile") % (nkey, )
95
+                  "see ringfile"), nkey
96 96
             )
97 97
             return []
98 98
         return map(lambda x: (key + '.' + x, x), self.ring[nkey])

+ 4
- 6
oslo/messaging/notify/_impl_routing.py View File

@@ -70,17 +70,15 @@ class RoutingDriver(notifier._Driver):
70 70
         for group in self.routing_groups.values():
71 71
             self.used_drivers.update(group.keys())
72 72
 
73
-        LOG.debug('loading notifiers from %(namespace)s' %
74
-                  {'namespace': self.NOTIFIER_PLUGIN_NAMESPACE})
73
+        LOG.debug('loading notifiers from %s', self.NOTIFIER_PLUGIN_NAMESPACE)
75 74
         self.plugin_manager = dispatch.DispatchExtensionManager(
76 75
             namespace=self.NOTIFIER_PLUGIN_NAMESPACE,
77 76
             check_func=self._should_load_plugin,
78 77
             invoke_on_load=True,
79 78
             invoke_args=None)
80 79
         if not list(self.plugin_manager):
81
-            LOG.warning(_("Failed to load any notifiers "
82
-                          "for %(namespace)s") %
83
-                        {'namespace': self.NOTIFIER_PLUGIN_NAMESPACE})
80
+            LOG.warning(_("Failed to load any notifiers for %s"),
81
+                        self.NOTIFIER_PLUGIN_NAMESPACE)
84 82
 
85 83
     def _get_drivers_for_message(self, group, event_type, priority):
86 84
         """Which drivers should be called for this event_type
@@ -116,7 +114,7 @@ class RoutingDriver(notifier._Driver):
116 114
         """Emit the notification.
117 115
         """
118 116
         # accepted_drivers is passed in as a result of the map() function
119
-        LOG.info(_("Routing '%(event)s' notification to '%(driver)s' driver") %
117
+        LOG.info(_("Routing '%(event)s' notification to '%(driver)s' driver"),
120 118
                  {'event': message.get('event_type'), 'driver': ext.name})
121 119
         ext.obj.notify(context, message, priority, retry)
122 120
 

+ 1
- 1
oslo/messaging/notify/dispatcher.py View File

@@ -108,7 +108,7 @@ class NotificationDispatcher(object):
108 108
         }
109 109
         priority = message.get('priority', '').lower()
110 110
         if priority not in PRIORITIES:
111
-            LOG.warning('Unknown priority "%s"' % priority)
111
+            LOG.warning('Unknown priority "%s"', priority)
112 112
             return
113 113
 
114 114
         payload = self.serializer.deserialize_entity(ctxt,

+ 1
- 1
oslo/messaging/rpc/dispatcher.py View File

@@ -133,7 +133,7 @@ class RPCDispatcher(object):
133 133
             incoming.reply(self._dispatch(incoming.ctxt,
134 134
                                           incoming.message))
135 135
         except ExpectedException as e:
136
-            LOG.debug(u'Expected exception during message handling (%s)' %
136
+            LOG.debug(u'Expected exception during message handling (%s)',
137 137
                       e.exc_info[1])
138 138
             incoming.reply(failure=e.exc_info, log_failure=False)
139 139
         except Exception as e:

+ 2
- 1
tests/test_notify_dispatcher.py View File

@@ -145,4 +145,5 @@ class TestDispatcher(test_utils.BaseTestCase):
145 145
             [mock.Mock()], [mock.Mock()], None, allow_requeue=True)
146 146
         with dispatcher(mock.Mock(ctxt={}, message=msg)) as callback:
147 147
             callback()
148
-        mylog.warning.assert_called_once_with('Unknown priority "what???"')
148
+        mylog.warning.assert_called_once_with('Unknown priority "%s"',
149
+                                              'what???')

Loading…
Cancel
Save