Don't use format() for logging

This commit is contained in:
Adrian Moennich 2016-01-25 13:34:49 +01:00
parent 90ddd7ce1a
commit 06ff5e763b
10 changed files with 44 additions and 46 deletions

View File

@ -44,7 +44,7 @@ def create_room(room):
muc.joinMUC(room.jid, xmpp.requested_jid.user)
muc.configureRoom(room.jid, _set_form_values(xmpp, room))
current_plugin.logger.info('Creating room {}'.format(room.jid))
current_plugin.logger.info('Creating room %s', room.jid)
_execute_xmpp(_create_room)
@ -59,7 +59,7 @@ def update_room(room):
muc.joinMUC(room.jid, xmpp.requested_jid.user)
muc.configureRoom(room.jid, _set_form_values(xmpp, room, muc.getRoomConfig(room.jid)))
current_plugin.logger.info('Updating room {}'.format(room.jid))
current_plugin.logger.info('Updating room %s', room.jid)
_execute_xmpp(_update_room)
@ -73,7 +73,7 @@ def delete_room(room, reason=''):
muc = xmpp.plugin['xep_0045']
muc.destroy(room.jid, reason=reason)
current_plugin.logger.info('Deleting room {}'.format(room.jid))
current_plugin.logger.info('Deleting room %s', room.jid)
_execute_xmpp(_delete_room)
delete_logs(room)
@ -189,7 +189,7 @@ def _execute_xmpp(connected_callback):
except Exception as e:
result[1] = e
if isinstance(e, IqError):
current_plugin.logger.exception('XMPP callback failed: {}'.format(e.condition))
current_plugin.logger.exception('XMPP callback failed: %s', e.condition)
else:
current_plugin.logger.exception('XMPP callback failed')
finally:
@ -242,11 +242,10 @@ def retrieve_logs(room, start_date=None, end_date=None):
try:
response = requests.get(base_url, params=params)
except RequestException:
current_plugin.logger.exception('Could not retrieve logs for {}'.format(room.jid))
current_plugin.logger.exception('Could not retrieve logs for %s', room.jid)
return None
if response.headers.get('content-type') == 'application/json':
current_plugin.logger.warning('Could not retrieve logs for {}: {}'.format(room.jid,
response.json().get('error')))
current_plugin.logger.warning('Could not retrieve logs for %s: %s', room.jid, response.json().get('error'))
return None
return response.text
@ -262,7 +261,7 @@ def delete_logs(room):
try:
response = requests.get(posixpath.join(base_url, 'delete'), params={'cr': room.jid}).json()
except (RequestException, ValueError):
current_plugin.logger.exception('Could not delete logs for {}'.format(room.jid))
current_plugin.logger.exception('Could not delete logs for %s', room.jid)
return
if not response.get('success'):
current_plugin.logger.warning('Could not delete logs for {}: {}'.format(room.jid), response.get('error'))
current_plugin.logger.warning('Could not delete logs for %s: %s', room.jid, response.get('error'))

View File

@ -96,7 +96,7 @@ class LiveSyncBackendBase(object):
records = self.fetch_records()
uploader = self.uploader(self)
LiveSyncPlugin.logger.info('Uploading {} records'.format(len(records)))
LiveSyncPlugin.logger.info('Uploading %d records', len(records))
uploader.run(records)
self.update_last_run()

View File

@ -58,7 +58,7 @@ class MARCXMLGenerator:
try:
self.add_object(ref, deleted)
except Exception:
current_plugin.logger.exception('Could not process {}'.format(ref))
current_plugin.logger.exception('Could not process %s', ref)
def add_object(self, ref, deleted=False):
if self.closed:

View File

@ -31,11 +31,11 @@ def scheduled_update():
clean_old_entries()
for agent in LiveSyncAgent.find_all():
if agent.backend is None:
LiveSyncPlugin.logger.warning('Skipping agent {}; backend not found'.format(agent.name))
LiveSyncPlugin.logger.warning('Skipping agent %s; backend not found', agent.name)
continue
if not agent.initial_data_exported:
LiveSyncPlugin.logger.warning('Skipping agent {}; initial export not performed yet'.format(agent.name))
LiveSyncPlugin.logger.warning('Skipping agent %s; initial export not performed yet', agent.name)
continue
LiveSyncPlugin.logger.info('Running agent {}'.format(agent.name))
LiveSyncPlugin.logger.info('Running agent %s', agent.name)
agent.create_backend().run()
db.session.commit()

View File

@ -42,18 +42,18 @@ class Uploader(object):
"""
self_name = type(self).__name__
for i, batch in enumerate(grouper(records, self.BATCH_SIZE, skip_missing=True), 1):
self.logger.info('{} processing batch {}'.format(self_name, i))
self.logger.info('%s processing batch %d', self_name, i)
try:
for j, proc_batch in enumerate(grouper(
process_records(batch).iteritems(), self.BATCH_SIZE, skip_missing=True), 1):
self.logger.info('{} uploading chunk #{} (batch {})'.format(self_name, j, i))
self.logger.info('%s uploading chunk #%d (batch %d)', self_name, j, i)
self.upload_records({k: v for k, v in proc_batch}, from_queue=True)
except Exception:
self.logger.exception('{} could not upload batch'.format(self_name))
self.logger.exception('%s could not upload batch', self_name)
return
self.logger.info('{} finished batch {}'.format(self_name, i))
self.logger.info('%s finished batch %d', self_name, i)
self.processed_records(batch)
self.logger.info('{} finished'.format(self_name))
self.logger.info('%s finished', self_name)
def run_initial(self, events):
"""Runs the initial batch upload
@ -62,11 +62,11 @@ class Uploader(object):
"""
self_name = type(self).__name__
for i, batch in enumerate(grouper(events, self.INITIAL_BATCH_SIZE, skip_missing=True), 1):
self.logger.debug('{} processing initial batch {}'.format(self_name, i))
self.logger.debug('%s processing initial batch %d', self_name, i)
for j, processed_batch in enumerate(grouper(
batch, self.BATCH_SIZE, skip_missing=True), 1):
self.logger.info('{} uploading initial chunk #{} (batch {})'.format(self_name, j, i))
self.logger.info('%s uploading initial chunk #%d (batch %d)', self_name, j, i)
self.upload_records(processed_batch, from_queue=False)
def upload_records(self, records, from_queue):
@ -84,7 +84,7 @@ class Uploader(object):
:param records: a list of queue entries
"""
for record in records:
self.logger.debug('Marking as processed: {}'.format(record))
self.logger.debug('Marking as processed: %s', record)
record.processed = True
db.session.commit()
transaction.abort() # clear ZEO cache

View File

@ -55,24 +55,23 @@ class RHPaypalIPN(RH):
verify_params = list(chain(IPN_VERIFY_EXTRA_PARAMS, request.form.iteritems()))
result = requests.post(current_plugin.settings.get('url'), data=verify_params).text
if result != 'VERIFIED':
current_plugin.logger.warning("Paypal IPN string {} did not validate ({})".format(verify_params, result))
current_plugin.logger.warning("Paypal IPN string %s did not validate (%s)", verify_params, result)
return
if self._is_transaction_duplicated():
current_plugin.logger.info("Payment not recorded because transaction was duplicated\n"
"Data received: {}".format(request.form))
current_plugin.logger.info("Payment not recorded because transaction was duplicated\nData received: %s",
request.form)
return
payment_status = request.form.get('payment_status')
if payment_status == 'Failed':
current_plugin.logger.info("Payment failed (status: {})\n"
"Data received: {}".format(payment_status, request.form))
current_plugin.logger.info("Payment failed (status: %s)\nData received: %s", payment_status, request.form)
return
if payment_status == 'Refunded' or float(request.form.get('mc_gross')) <= 0:
current_plugin.logger.warning("Payment refunded (status: {})\n"
"Data received: {}".format(payment_status, request.form))
current_plugin.logger.warning("Payment refunded (status: %s)\nData received: %s",
payment_status, request.form)
return
if payment_status not in paypal_transaction_action_mapping:
current_plugin.logger.warning("Payment status '{}' not recognized\n"
"Data received: {}".format(payment_status, request.form))
current_plugin.logger.warning("Payment status '%s' not recognized\nData received: %s",
payment_status, request.form)
return
self._verify_amount()
register_transaction(registration=self.registration,
@ -87,8 +86,8 @@ class RHPaypalIPN(RH):
business = request.form.get('business')
if expected == business:
return True
current_plugin.logger.warning("Unexpected business: {} != {}".format(business, expected))
current_plugin.logger.warning("Request data was: {}".format(request.form))
current_plugin.logger.warning("Unexpected business: %s != %s", business, expected)
current_plugin.logger.warning("Request data was: %s", request.form)
return False
def _verify_amount(self):
@ -98,8 +97,8 @@ class RHPaypalIPN(RH):
currency = request.form['mc_currency']
if expected_amount == amount and expected_currency == currency:
return True
current_plugin.logger.warning("Payment doesn't match event's fee: {} {} != {} {}"
.format(amount, currency, expected_amount, expected_currency))
current_plugin.logger.warning("Payment doesn't match event's fee: %s %s != %s %s",
amount, currency, expected_amount, expected_currency)
notify_amount_inconsistency(self.registration, amount, currency)
return False

View File

@ -43,7 +43,7 @@ class PiwikQueryReportEventGraphBase(PiwikQueryReportEventBase):
if png is None:
return
if png.startswith('GD extension must be loaded'):
current_plugin.logger.warning('Piwik server answered on ImageGraph.get: {}'.format(png))
current_plugin.logger.warning('Piwik server answered on ImageGraph.get: %s', png)
return
return 'data:image/png;base64,{}'.format(b64encode(png))

View File

@ -28,11 +28,11 @@ def get_json_from_remote_server(func, default={}, **kwargs):
try:
data = json.loads(rawjson)
if isinstance(data, dict) and data.get('result') == 'error':
current_plugin.logger.error('The Piwik server responded with an error: {}'.format(data['message']))
current_plugin.logger.error('The Piwik server responded with an error: %s', data['message'])
return {}
return data
except Exception:
current_plugin.logger.exception('Unable to load JSON from source {}'.format(str(rawjson)))
current_plugin.logger.exception('Unable to load JSON from source %s', rawjson)
return default

View File

@ -69,7 +69,7 @@ class SearchResult(object):
def is_visible(self, user):
obj = self.object
if not obj:
current_plugin.logger.warning('referenced element {} does not exist'.format(self.compound_id))
current_plugin.logger.warning('referenced element %s does not exist', self.compound_id)
return False
return obj.canView(AccessWrapper(user.as_avatar if user else None))

View File

@ -60,24 +60,24 @@ def vidyo_cleanup(dry_run=False):
from indico_vc_vidyo.plugin import VidyoPlugin
max_room_event_age = VidyoPlugin.settings.get('num_days_old')
VidyoPlugin.logger.info('Deleting Vidyo rooms that are not used or linked to events all older than {} days'
.format(max_room_event_age))
VidyoPlugin.logger.info('Deleting Vidyo rooms that are not used or linked to events all older than %d days',
max_room_event_age)
candidate_rooms = find_old_vidyo_rooms(max_room_event_age)
VidyoPlugin.logger.info('{} rooms found'.format(len(candidate_rooms)))
VidyoPlugin.logger.info('%d rooms found', len(candidate_rooms))
if dry_run:
for vc_room in candidate_rooms:
VidyoPlugin.logger.info('Would delete Vidyo room {} from server'.format(vc_room))
VidyoPlugin.logger.info('Would delete Vidyo room %s from server', vc_room)
return
for vc_room in committing_iterator(candidate_rooms, n=20):
try:
VidyoPlugin.instance.delete_room(vc_room, None)
VidyoPlugin.logger.info('Room {} deleted from Vidyo server'.format(vc_room))
VidyoPlugin.logger.info('Room %s deleted from Vidyo server', vc_room)
notify_owner(VidyoPlugin.instance, vc_room)
vc_room.status = VCRoomStatus.deleted
except RoomNotFoundAPIException:
VidyoPlugin.logger.warning('Room {} had been already deleted from the Vidyo server'.format(vc_room))
VidyoPlugin.logger.warning('Room %s had been already deleted from the Vidyo server', vc_room)
vc_room.status = VCRoomStatus.deleted
except APIException:
VidyoPlugin.logger.exception('Impossible to delete Vidyo room {}'.format(vc_room))
VidyoPlugin.logger.exception('Impossible to delete Vidyo room %s', vc_room)