Merge "feat(logging): format msg when log level met"
This commit is contained in:
commit
ea79e2bd16
@ -87,9 +87,9 @@ class Pipeline(object):
|
||||
target = getattr(stage, method)
|
||||
except AttributeError:
|
||||
sstage = six.text_type(stage)
|
||||
msg = _(u"Stage {0} does not implement {1}").format(sstage,
|
||||
method)
|
||||
LOG.warning(msg)
|
||||
msgtmpl = _(u"Stage %(stage)s does not "
|
||||
"implement %(method)s")
|
||||
LOG.warning(msgtmpl, {'stage': sstage, 'method': method})
|
||||
continue
|
||||
|
||||
result = target(*args, **kwargs)
|
||||
@ -101,8 +101,8 @@ class Pipeline(object):
|
||||
return result
|
||||
|
||||
if target is None:
|
||||
msg = _(u'Method {0} not found in any of '
|
||||
'the registered stages').format(method)
|
||||
msg = _(u'Method %s not found in any of '
|
||||
'the registered stages') % method
|
||||
LOG.error(msg)
|
||||
raise AttributeError(msg)
|
||||
|
||||
|
@ -76,7 +76,7 @@ def validate_queue_name(validate, req, resp, params):
|
||||
queue = params['queue_name'].decode('utf-8', 'replace')
|
||||
|
||||
LOG.warn(_(u'Invalid queue name "%(queue)s" submitted for '
|
||||
u'project: %(project)s') %
|
||||
u'project: %(project)s'),
|
||||
{'queue': queue, 'project': project})
|
||||
|
||||
info = six.text_type(ex) or _(u'The format of the submitted '
|
||||
|
@ -87,7 +87,7 @@ class Bootstrap(object):
|
||||
@decorators.lazy_property(write=False)
|
||||
def transport(self):
|
||||
transport_name = self.driver_conf.transport
|
||||
LOG.debug(_(u'Loading transport driver: ') + transport_name)
|
||||
LOG.debug(_(u'Loading transport driver: %s'), transport_name)
|
||||
|
||||
try:
|
||||
mgr = driver.DriverManager(self._transport_type,
|
||||
|
@ -478,13 +478,15 @@ class MessageController(storage.MessageBase):
|
||||
|
||||
# Log a message if we retried, for debugging perf issues
|
||||
if attempt != 0:
|
||||
message = _(u'%(attempts)d attempt(s) required to post '
|
||||
msgtmpl = _(u'%(attempts)d attempt(s) required to post '
|
||||
u'%(num_messages)d messages to queue '
|
||||
u'"%(queue)s" under project %(project)s')
|
||||
message %= dict(queue=queue_name, attempts=attempt+1,
|
||||
num_messages=len(ids), project=project)
|
||||
|
||||
LOG.debug(message)
|
||||
LOG.debug(msgtmpl,
|
||||
dict(queue=queue_name,
|
||||
attempts=attempt + 1,
|
||||
num_messages=len(ids),
|
||||
project=project))
|
||||
|
||||
# Update the counter in preparation for the next batch
|
||||
#
|
||||
@ -513,12 +515,11 @@ class MessageController(storage.MessageBase):
|
||||
#
|
||||
# TODO(kgriffs): Add transaction ID to help match up loglines
|
||||
if attempt == 0:
|
||||
message = _(u'First attempt failed while '
|
||||
msgtmpl = _(u'First attempt failed while '
|
||||
u'adding messages to queue '
|
||||
u'"%(queue)s" under project %(project)s')
|
||||
message %= dict(queue=queue_name, project=project)
|
||||
|
||||
LOG.debug(message)
|
||||
LOG.debug(msgtmpl, dict(queue=queue_name, project=project))
|
||||
|
||||
# NOTE(kgriffs): Never retry past the point that competing
|
||||
# messages expire and are GC'd, since once they are gone,
|
||||
@ -528,11 +529,11 @@ class MessageController(storage.MessageBase):
|
||||
# this situation can not happen.
|
||||
elapsed = timeutils.utcnow_ts() - now
|
||||
if elapsed > MAX_RETRY_POST_DURATION:
|
||||
message = _(u'Exceeded maximum retry duration for queue '
|
||||
msgtmpl = _(u'Exceeded maximum retry duration for queue '
|
||||
u'"%(queue)s" under project %(project)s')
|
||||
message %= dict(queue=queue_name, project=project)
|
||||
|
||||
LOG.warning(message)
|
||||
LOG.warning(msgtmpl,
|
||||
dict(queue=queue_name, project=project))
|
||||
break
|
||||
|
||||
# Chill out for a moment to mitigate thrashing/thundering
|
||||
@ -572,14 +573,14 @@ class MessageController(storage.MessageBase):
|
||||
next_marker = self._queue_ctrl._get_counter(
|
||||
queue_name, project)
|
||||
else:
|
||||
message = (u'Detected a stalled message counter for '
|
||||
msgtmpl = (u'Detected a stalled message counter for '
|
||||
u'queue "%(queue)s" under project %(project)s. '
|
||||
u'The counter was incremented to %(value)d.')
|
||||
message %= dict(queue=queue_name,
|
||||
project=project,
|
||||
value=next_marker)
|
||||
|
||||
LOG.warning(message)
|
||||
LOG.warning(msgtmpl,
|
||||
dict(queue=queue_name,
|
||||
project=project,
|
||||
value=next_marker))
|
||||
|
||||
for index, message in enumerate(prepared_messages):
|
||||
message['k'] = next_marker + index
|
||||
@ -592,13 +593,13 @@ class MessageController(storage.MessageBase):
|
||||
LOG.exception(ex)
|
||||
raise
|
||||
|
||||
message = _(u'Hit maximum number of attempts (%(max)s) for queue '
|
||||
msgtmpl = _(u'Hit maximum number of attempts (%(max)s) for queue '
|
||||
u'"%(queue)s" under project %(project)s')
|
||||
message %= dict(max=self.driver.mongodb_conf.max_attempts,
|
||||
queue=queue_name,
|
||||
project=project)
|
||||
|
||||
LOG.warning(message)
|
||||
LOG.warning(msgtmpl,
|
||||
dict(max=self.driver.mongodb_conf.max_attempts,
|
||||
queue=queue_name,
|
||||
project=project))
|
||||
|
||||
succeeded_ids = []
|
||||
raise exceptions.MessageConflict(queue_name, project, succeeded_ids)
|
||||
|
@ -147,12 +147,11 @@ class QueueController(storage.QueueBase):
|
||||
# NOTE(kgriffs): Since we did not filter by a time window,
|
||||
# the queue should have been found and updated. Perhaps
|
||||
# the queue has been deleted?
|
||||
message = _(u'Failed to increment the message '
|
||||
msgtmpl = _(u'Failed to increment the message '
|
||||
u'counter for queue %(name)s and '
|
||||
u'project %(project)s')
|
||||
message %= dict(name=name, project=project)
|
||||
|
||||
LOG.warning(message)
|
||||
LOG.warning(msgtmpl, dict(name=name, project=project))
|
||||
|
||||
raise exceptions.QueueDoesNotExist(name, project)
|
||||
|
||||
|
@ -72,9 +72,8 @@ def _get_storage_pipeline(resource_name, conf):
|
||||
ns, invoke_on_load=True)
|
||||
pipeline.append(mgr.driver)
|
||||
except RuntimeError as exc:
|
||||
msg = _('Stage {0} could not be imported: {1}').format(ns,
|
||||
str(exc))
|
||||
LOG.warning(msg)
|
||||
LOG.warning(_(u'Stage %(stage)d could not be imported: %(ex)s'),
|
||||
{'stage': ns, 'ex': str(exc)})
|
||||
continue
|
||||
|
||||
return common.Pipeline(pipeline)
|
||||
|
@ -43,7 +43,7 @@ class CollectionResource(Resource):
|
||||
|
||||
def on_post(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_(u'Claims collection POST - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
u'project: %(project)s'),
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
# Check for an explicit limit on the # of messages to claim
|
||||
@ -108,7 +108,7 @@ class ItemResource(Resource):
|
||||
|
||||
def on_get(self, req, resp, project_id, queue_name, claim_id):
|
||||
LOG.debug(_(u'Claim item GET - claim: %(claim_id)s, '
|
||||
u'queue: %(queue_name)s, project: %(project_id)s') %
|
||||
u'queue: %(queue_name)s, project: %(project_id)s'),
|
||||
{'queue_name': queue_name,
|
||||
'project_id': project_id,
|
||||
'claim_id': claim_id})
|
||||
|
@ -95,9 +95,9 @@ class DriverBase(transport.DriverBase):
|
||||
def listen(self):
|
||||
"""Self-host using 'bind' and 'port' from the WSGI config group."""
|
||||
|
||||
msg = _(u'Serving on host %(bind)s:%(port)s')
|
||||
msg %= {'bind': self._wsgi_conf.bind, 'port': self._wsgi_conf.port}
|
||||
LOG.info(msg)
|
||||
msgtmpl = _(u'Serving on host %(bind)s:%(port)s')
|
||||
LOG.info(msgtmpl,
|
||||
{'bind': self._wsgi_conf.bind, 'port': self._wsgi_conf.port})
|
||||
|
||||
httpd = simple_server.make_server(self._wsgi_conf.bind,
|
||||
self._wsgi_conf.port,
|
||||
|
@ -129,7 +129,7 @@ class CollectionResource(object):
|
||||
|
||||
def on_post(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_(u'Messages collection POST - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
u'project: %(project)s'),
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
client_uuid = wsgi_utils.get_client_uuid(req)
|
||||
@ -196,7 +196,7 @@ class CollectionResource(object):
|
||||
|
||||
def on_get(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_(u'Messages collection GET - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
u'project: %(project)s'),
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
resp.content_location = req.relative_uri
|
||||
@ -247,7 +247,7 @@ class ItemResource(object):
|
||||
|
||||
def on_get(self, req, resp, project_id, queue_name, message_id):
|
||||
LOG.debug(_(u'Messages item GET - message: %(message)s, '
|
||||
u'queue: %(queue)s, project: %(project)s') %
|
||||
u'queue: %(queue)s, project: %(project)s'),
|
||||
{'message': message_id,
|
||||
'queue': queue_name,
|
||||
'project': project_id})
|
||||
@ -275,7 +275,7 @@ class ItemResource(object):
|
||||
|
||||
def on_delete(self, req, resp, project_id, queue_name, message_id):
|
||||
LOG.debug(_(u'Messages item DELETE - message: %(message)s, '
|
||||
u'queue: %(queue)s, project: %(project)s') %
|
||||
u'queue: %(queue)s, project: %(project)s'),
|
||||
{'message': message_id,
|
||||
'queue': queue_name,
|
||||
'project': project_id})
|
||||
|
@ -37,7 +37,7 @@ class Resource(object):
|
||||
|
||||
def on_get(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_(u'Queue metadata GET - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
u'project: %(project)s'),
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
try:
|
||||
@ -58,7 +58,7 @@ class Resource(object):
|
||||
|
||||
def on_put(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_(u'Queue metadata PUT - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
u'project: %(project)s'),
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
# Place JSON size restriction before parsing
|
||||
|
@ -35,7 +35,7 @@ class ItemResource(object):
|
||||
|
||||
def on_put(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_(u'Queue item PUT - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
u'project: %(project)s'),
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
try:
|
||||
@ -52,7 +52,7 @@ class ItemResource(object):
|
||||
|
||||
def on_head(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_(u'Queue item exists - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
u'project: %(project)s'),
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
if self.queue_controller.exists(queue_name, project=project_id):
|
||||
@ -66,7 +66,7 @@ class ItemResource(object):
|
||||
|
||||
def on_delete(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_(u'Queue item DELETE - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
u'project: %(project)s'),
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
try:
|
||||
self.queue_controller.delete(queue_name, project=project_id)
|
||||
|
@ -64,7 +64,7 @@ class Listing(object):
|
||||
|
||||
:returns: HTTP | [200, 204]
|
||||
"""
|
||||
LOG.debug('LIST shards')
|
||||
LOG.debug(u'LIST shards')
|
||||
resp = list(self._ctrl.list())
|
||||
|
||||
if not resp:
|
||||
@ -97,7 +97,7 @@ class Resource(object):
|
||||
|
||||
:returns: HTTP | [200, 404]
|
||||
"""
|
||||
LOG.debug('GET shard - name: {0}'.format(shard))
|
||||
LOG.debug(u'GET shard - name: %s', shard)
|
||||
data = None
|
||||
try:
|
||||
data = self._ctrl.get(shard)
|
||||
@ -119,9 +119,9 @@ class Resource(object):
|
||||
|
||||
:returns: HTTP | [201, 204]
|
||||
"""
|
||||
LOG.debug('PUT shard - name: {0}'.format(shard))
|
||||
LOG.debug(u'PUT shard - name: %s', shard)
|
||||
if self._ctrl.exists(shard):
|
||||
LOG.debug('Shard {0} already exists'.format(shard))
|
||||
LOG.debug(u'Shard %s already exists', shard)
|
||||
response.status = falcon.HTTP_204
|
||||
return
|
||||
|
||||
@ -138,7 +138,7 @@ class Resource(object):
|
||||
|
||||
:returns: HTTP | 204
|
||||
"""
|
||||
LOG.debug('DELETE shard - name: {0}'.format(shard))
|
||||
LOG.debug(u'DELETE shard - name: %s', shard)
|
||||
self._ctrl.delete(shard)
|
||||
response.status = falcon.HTTP_204
|
||||
|
||||
@ -154,12 +154,12 @@ class Resource(object):
|
||||
|
||||
:returns: HTTP | 200,400
|
||||
"""
|
||||
LOG.debug('PATCH shard - name: {0}'.format(shard))
|
||||
LOG.debug(u'PATCH shard - name: %s', shard)
|
||||
data = utils.load(request)
|
||||
|
||||
EXPECT = ('weight', 'location', 'options')
|
||||
if not any([(field in data) for field in EXPECT]):
|
||||
LOG.debug('PATCH shard, bad params')
|
||||
LOG.debug(u'PATCH shard, bad params')
|
||||
raise wsgi_errors.HTTPBadRequestBody(
|
||||
'One of `location`, `weight`, or `options` needs '
|
||||
'to be specified'
|
||||
|
Loading…
x
Reference in New Issue
Block a user