Python 3 deprecated the logger.warn method in favor of warning

Python 3 deprecated the logger.warn method, please see:
https://docs.python.org/3/library/logging.html#logging.warning,
so we prefer to use warning to avoid DeprecationWarning.

Change-Id: I55148140bb2e85039356726057ae1d552e69b663
This commit is contained in:
ChangBo Guo(gcb) 2015-12-26 16:18:56 +08:00
parent a84412dd16
commit 2d2f6ca5d2
8 changed files with 43 additions and 41 deletions

View File

@ -168,9 +168,9 @@ class ObsoleteReplyQueuesCache(object):
self._no_reply_log(reply_q, msg_id)
def _no_reply_log(self, reply_q, msg_id):
LOG.warn(_LW("%(reply_queue)s doesn't exists, drop reply to "
"%(msg_id)s"), {'reply_queue': reply_q,
'msg_id': msg_id})
LOG.warning(_LW("%(reply_queue)s doesn't exists, drop reply to "
"%(msg_id)s"), {'reply_queue': reply_q,
'msg_id': msg_id})
class AMQPListener(base.Listener):
@ -251,11 +251,11 @@ class ReplyWaiters(object):
def add(self, msg_id):
self._queues[msg_id] = moves.queue.Queue()
if len(self._queues) > self._wrn_threshold:
LOG.warn(_LW('Number of call queues is greater than warning '
'threshold: %(old_threshold)s. There could be a '
'leak. Increasing threshold to: %(threshold)s'),
{'old_threshold': self._wrn_threshold,
'threshold': self._wrn_threshold * 2})
LOG.warning(_LW('Number of call queues is greater than warning '
'threshold: %(old_threshold)s. There could be a '
'leak. Increasing threshold to: %(threshold)s'),
{'old_threshold': self._wrn_threshold,
'threshold': self._wrn_threshold * 2})
self._wrn_threshold *= 2
def remove(self, msg_id):

View File

@ -132,7 +132,8 @@ class Connection(object):
self._send(message, topic)
message = None
except Exception:
LOG.warn(_LW("Failed to publish a message of topic %s"), topic)
LOG.warning(_LW("Failed to publish a message of topic %s"),
topic)
current_retry += 1
if retry is not None and current_retry >= retry:
LOG.exception(_LE("Failed to retry to send data "
@ -238,10 +239,10 @@ class OsloKafkaMessage(base.IncomingMessage):
super(OsloKafkaMessage, self).__init__(listener, ctxt, message)
def requeue(self):
LOG.warn(_LW("requeue is not supported"))
LOG.warning(_LW("requeue is not supported"))
def reply(self, reply=None, failure=None, log_failure=True):
LOG.warn(_LW("reply is not supported"))
LOG.warning(_LW("reply is not supported"))
class KafkaListener(base.Listener):

View File

@ -433,15 +433,16 @@ class Connection(object):
self._url = ''
if self.fake_rabbit:
LOG.warn(_LW("Deprecated: fake_rabbit option is deprecated, set "
"rpc_backend to kombu+memory or use the fake "
"driver instead."))
LOG.warning(_LW("Deprecated: fake_rabbit option is deprecated, "
"set rpc_backend to kombu+memory or use the fake "
"driver instead."))
self._url = 'memory://%s/' % virtual_host
elif url.hosts:
if url.transport.startswith('kombu+'):
LOG.warn(_LW('Selecting the kombu transport through the '
'transport url (%s) is a experimental feature '
'and this is not yet supported.'), url.transport)
LOG.warning(_LW('Selecting the kombu transport through the '
'transport url (%s) is a experimental feature '
'and this is not yet supported.'),
url.transport)
if len(url.hosts) > 1:
random.shuffle(url.hosts)
for host in url.hosts:
@ -631,10 +632,10 @@ class Connection(object):
current_pid = os.getpid()
if self._initial_pid != current_pid:
LOG.warn(_LW("Process forked after connection established! "
"This can result in unpredictable behavior. "
"See: http://docs.openstack.org/developer/"
"oslo.messaging/transport.html"))
LOG.warning(_LW("Process forked after connection established! "
"This can result in unpredictable behavior. "
"See: http://docs.openstack.org/developer/"
"oslo.messaging/transport.html"))
self._initial_pid = current_pid
if retry is None:
@ -780,8 +781,8 @@ class Connection(object):
if self.connection.supports_heartbeats:
return True
elif not self._heartbeat_support_log_emitted:
LOG.warn(_LW("Heartbeat support requested but it is not supported "
"by the kombu driver or the broker"))
LOG.warning(_LW("Heartbeat support requested but it is not "
"supported by the kombu driver or the broker"))
self._heartbeat_support_log_emitted = True
return False

View File

@ -142,8 +142,8 @@ class Replies(pyngus.ReceiverEventHandler):
del self._correlation[key]
receiver.message_accepted(handle)
else:
LOG.warn(_LW("Can't find receiver for response msg id=%s, "
"dropping!"), key)
LOG.warning(_LW("Can't find receiver for response msg id=%s, "
"dropping!"), key)
receiver.message_modified(handle, True, True, None)
def _update_credit(self):

View File

@ -62,8 +62,8 @@ class SendTask(controller.Task):
controller.request(self._target, self._request,
self._results_queue, self._wait_for_reply)
else:
LOG.warn(_LW("Send request to %s aborted: TTL expired."),
self._target)
LOG.warning(_LW("Send request to %s aborted: TTL expired."),
self._target)
class ListenTask(controller.Task):

View File

@ -301,7 +301,7 @@ class CheckForLoggingIssues(BaseASTChecker):
# because:
# 1. We have code like this that we'll fix when dealing with the %:
# msg = _('....') % {}
# LOG.warn(msg)
# LOG.warning(msg)
# 2. We also do LOG.exception(e) in several places. I'm not sure
# exactly what we should be doing about that.
if msg.id not in self.assignments:

View File

@ -112,7 +112,7 @@ class _OrderedTask(object):
while condition():
if log_timer is not None and log_timer.expired():
LOG.warn(_LW('Possible hang: %s'), msg)
LOG.warning(_LW('Possible hang: %s'), msg)
LOG.debug(''.join(traceback.format_stack()))
# Only log once. After than we wait indefinitely without
# logging.
@ -346,11 +346,11 @@ class MessageHandlingServer(service.ServiceBase, _OrderedTaskRunner):
"""
# Warn that restarting will be deprecated
if self._started:
LOG.warn(_LW('Restarting a MessageHandlingServer is inherently '
'racy. It is deprecated, and will become a noop in '
'a future release of oslo.messaging. If you need to '
'restart MessageHandlingServer you should '
'instantiate a new object.'))
LOG.warning(_LW('Restarting a MessageHandlingServer is inherently '
'racy. It is deprecated, and will become a noop '
'in a future release of oslo.messaging. If you '
'need to restart MessageHandlingServer you should '
'instantiate a new object.'))
self._started = True
try:

View File

@ -744,14 +744,14 @@ class TestServerLocking(test_utils.BaseTestCase):
# DEFAULT_LOG_AFTER
log_event = threading.Event()
mock_log.warn.side_effect = lambda _, __: log_event.set()
mock_log.warning.side_effect = lambda _, __: log_event.set()
# Call stop without calling start. We should log a wait after 1 second
thread = eventlet.spawn(self.server.stop)
log_event.wait()
# Redundant given that we already waited, but it's nice to assert
self.assertTrue(mock_log.warn.called)
self.assertTrue(mock_log.warning.called)
thread.kill()
@mock.patch.object(server_module, 'LOG')
@ -760,14 +760,14 @@ class TestServerLocking(test_utils.BaseTestCase):
# the number of seconds passed to log_after
log_event = threading.Event()
mock_log.warn.side_effect = lambda _, __: log_event.set()
mock_log.warning.side_effect = lambda _, __: log_event.set()
# Call stop without calling start. We should log a wait after 1 second
thread = eventlet.spawn(self.server.stop, log_after=1)
log_event.wait()
# Redundant given that we already waited, but it's nice to assert
self.assertTrue(mock_log.warn.called)
self.assertTrue(mock_log.warning.called)
thread.kill()
@mock.patch.object(server_module, 'LOG')
@ -776,14 +776,14 @@ class TestServerLocking(test_utils.BaseTestCase):
# specified an absolute timeout
log_event = threading.Event()
mock_log.warn.side_effect = lambda _, __: log_event.set()
mock_log.warning.side_effect = lambda _, __: log_event.set()
# Call stop without calling start. We should log a wait after 1 second
thread = eventlet.spawn(self.server.stop, log_after=1, timeout=2)
log_event.wait()
# Redundant given that we already waited, but it's nice to assert
self.assertTrue(mock_log.warn.called)
self.assertTrue(mock_log.warning.called)
thread.kill()
def test_timeout_wait(self):
@ -829,4 +829,4 @@ class TestServerLocking(test_utils.BaseTestCase):
self.server.stop, log_after=0, timeout=2)
# We timed out. Ensure we didn't log anything.
self.assertFalse(mock_log.warn.called)
self.assertFalse(mock_log.warning.called)