Skip to content

Commit

Permalink
Append variable data as arguments for logging format string
Browse files Browse the repository at this point in the history
  • Loading branch information
andbag committed Jul 11, 2018
1 parent bad4ff4 commit 3b2504d
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 62 deletions.
19 changes: 10 additions & 9 deletions src/Products/PluginIndexes/BooleanIndex/BooleanIndex.py
Expand Up @@ -136,12 +136,13 @@ def removeForwardIndexEntry(self, entry, documentId, check=True):
except ConflictError:
raise
except Exception:
LOG.exception(
'{0}: unindex_object could not remove documentId {1} '
'from index {2}. This should not happen.'.format(
self.__class__.__name__,
str(documentId),
str(self.id)))
LOG.exception('%(context)s: unindex_object could not '
'remove documentId %(doc_id)s from '
'index %(index)r. This should not '
'happen.', dict(
context=self.__class__.__name__,
doc_id=documentId,
index=self.id))
elif check:
# is the index (after removing the current entry) larger than
# 60% of the total length? than switch the indexed value
Expand Down Expand Up @@ -174,8 +175,8 @@ def _index_object(self, documentId, obj, threshold=None, attr=''):
raise
except Exception:
LOG.error('Should not happen: oldDatum was there, now '
'its not, for document with id {0}'.format(
documentId))
'its not, for document with id %s',
documentId)

if datum is not _marker:
self.insertForwardIndexEntry(datum, documentId)
Expand Down Expand Up @@ -203,7 +204,7 @@ def unindex_object(self, documentId):
raise
except Exception:
LOG.debug('Attempt to unindex nonexistent document'
' with id {0}'.format(documentId), exc_info=True)
' with id %s', documentId, exc_info=True)

def query_index(self, record, resultset=None):
index = self._index
Expand Down
6 changes: 4 additions & 2 deletions src/Products/PluginIndexes/CompositeIndex/CompositeIndex.py
Expand Up @@ -304,8 +304,10 @@ def make_query(self, query):
zc = aq_parent(aq_parent(self))
skip = zc.getProperty('skip_compositeindex', False)
if skip:
LOG.debug('{0}: skip composite query build {1}'.format(
self.__class__.__name__, repr(zc)))
LOG.debug('%(context)s: skip composite query build '
'for %(zcatalog)r', dict(
context=self.__class__.__name__,
zcatalog=zc))
return query
except AttributeError:
pass
Expand Down
Expand Up @@ -132,8 +132,8 @@ def defaultSearch(self, req, expectedValues=None, verbose=False):
break

if verbose and (index.id in req):
logger.info("index %s: %s hits in %3.2fms" %
(index.id, r and len(r) or 0, duration))
logger.info('index %s: %s hits in %3.2fms',
index.id, r and len(r) or 0, duration)

if not rs:
return set()
Expand Down Expand Up @@ -168,8 +168,8 @@ def info(index):
n_obj = index.numObjects()
ratio = float(size) / float(n_obj)
logger.info('<id: %15s unique keys: '
'%3s length: %5s ratio: %6.3f pm>' %
(index.id, size, n_obj, ratio * 1000))
'%3s length: %5s ratio: %6.3f pm>',
index.id, size, n_obj, ratio * 1000)
return ratio

for index in self._indexes:
Expand Down Expand Up @@ -256,20 +256,20 @@ def profileSearch(query, warmup=False, verbose=False):
duration1 = (time() - st) * 1000

if verbose:
logger.info("atomic: %s hits in %3.2fms" %
(len(res1), duration1))
logger.info('atomic: %s hits in %3.2fms',
len(res1), duration1)

st = time()
res2 = self.compositeSearch(query, verbose=False)
duration2 = (time() - st) * 1000

if verbose:
logger.info("composite: %s hits in %3.2fms" %
(len(res2), duration2))
logger.info('composite: %s hits in %3.2fms',
len(res2), duration2)

if verbose:
logger.info('[composite/atomic] factor %3.2f' %
(duration1 / duration2,))
logger.info('[composite/atomic] factor %3.2f',
duration1 / duration2,)

if not warmup:
# if length of result is greater than zero composite
Expand All @@ -285,7 +285,7 @@ def profileSearch(query, warmup=False, verbose=False):
for l in lengths:
self.clearIndexes()
logger.info('************************************\n'
'indexing %s objects' % l)
'indexing %s objects', l)

for i in range(l):
name = '%s' % i
Expand All @@ -299,14 +299,14 @@ def profileSearch(query, warmup=False, verbose=False):
logger.info('\nstart queries')

# warming up indexes
logger.info("warming up indexes")
logger.info('warming up indexes')
for name, query in queries:
profileSearch(query, warmup=True)

# in memory measure
logger.info("in memory measure")
logger.info('in memory measure')
for name, query in queries:
logger.info("\nquery: %s" % name)
logger.info('\nquery: %s', name)
profileSearch(query, verbose=True)

logger.info('\nqueries finished')
Expand Down
2 changes: 1 addition & 1 deletion src/Products/PluginIndexes/DateIndex/DateIndex.py
Expand Up @@ -144,7 +144,7 @@ def index_object(self, documentId, obj, threshold=None):
except Exception:
LOG.error('Should not happen: ConvertedDate was there,'
' now it\'s not, for document'
' with id {0}'.format(documentId))
' with id %s', documentId)

if ConvertedDate is not _marker:
self.insertForwardIndexEntry(ConvertedDate, documentId)
Expand Down
7 changes: 4 additions & 3 deletions src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py
Expand Up @@ -134,9 +134,10 @@ def unindex_object(self, documentId):
try:
del self._unindex[documentId]
except KeyError:
LOG.debug('{0}: Attempt to unindex nonexistent '
'document with id {1}'.format(
self.__class__.__name__, documentId),
LOG.debug('%(context)s: Attempt to unindex nonexistent '
'document with id %(doc_id)s', dict(
context=self.__class__.__name__,
doc_id=documentId),
exc_info=True)

manage = manage_main = DTMLFile('dtml/manageKeywordIndex', globals())
Expand Down
6 changes: 2 additions & 4 deletions src/Products/PluginIndexes/PathIndex/PathIndex.py
Expand Up @@ -135,8 +135,7 @@ def unindex_object(self, docid):
"""
if docid not in self._unindex:
LOG.debug('Attempt to unindex nonexistent '
'document with id {0}'.format(
docid))
'document with id %s', docid)

return

Expand All @@ -153,8 +152,7 @@ def unindex_object(self, docid):
del self._index[comp]
except KeyError:
LOG.debug('Attempt to unindex document '
'with id {0} failed'.format(
docid))
'with id %s failed', docid)

self._length.change(-1)
del self._unindex[docid]
Expand Down
4 changes: 2 additions & 2 deletions src/Products/PluginIndexes/TopicIndex/FilteredSet.py
Expand Up @@ -89,8 +89,8 @@ def index_object(self, documentId, o):
except ConflictError:
raise
except Exception:
LOG.warn('eval() failed Object: {0}, expr: {1}'.format(
o.getId(), self.expr), exc_info=sys.exc_info())
LOG.warn('eval() failed Object: %s, expr: %s',
o.getId(), self.expr, exc_info=sys.exc_info())


def factory(f_id, f_type, expr):
Expand Down
2 changes: 1 addition & 1 deletion src/Products/PluginIndexes/TopicIndex/TopicIndex.py
Expand Up @@ -74,7 +74,7 @@ def unindex_object(self, docid):
fs.unindex_object(docid)
except KeyError:
LOG.debug('Attempt to unindex document'
' with id {0} failed'.format(docid))
' with id %s failed', docid)
return 1

def numObjects(self):
Expand Down
4 changes: 2 additions & 2 deletions src/Products/PluginIndexes/UUIDIndex/UUIDIndex.py
Expand Up @@ -95,8 +95,8 @@ def insertForwardIndexEntry(self, entry, documentId):
self._index[entry] = documentId
self._length.change(1)
elif old_docid != documentId:
logger.error("A different document with value '{0}' already "
"exists in the index.'".format(entry))
logger.error("A different document with value '%s' already "
'exists in the index.', entry)

def removeForwardIndexEntry(self, entry, documentId):
"""Take the entry provided and remove any reference to documentId
Expand Down
33 changes: 17 additions & 16 deletions src/Products/PluginIndexes/unindex.py
Expand Up @@ -191,18 +191,20 @@ def removeForwardIndexEntry(self, entry, documentId):
del self.__len__
self._length.change(-1)
except Exception:
LOG.error('{0}: unindex_object could not remove '
'documentId {1} from index {2}. This '
'should not happen.'.format(
self.__class__.__name__,
str(documentId), str(self.id)),
LOG.error('%(context)s: unindex_object could not remove '
'documentId %(doc_id)s from index %(index)r. This '
'should not happen.', dict(
context=self.__class__.__name__,
doc_id=documentId,
index=self.id),
exc_info=sys.exc_info())
else:
LOG.error('{0}: unindex_object tried to retrieve set {1} '
'from index {2} but couldn\'t. This '
'should not happen.'.format(
self.__class__.__name__,
repr(entry), str(self.id)))
LOG.error('%(context)s: unindex_object tried to '
'retrieve set %(entry)r from index %(index)r '
'but couldn\'t. This should not happen.', dict(
context=self.__class__.__name__,
entry=entry,
index=self.id))

def insertForwardIndexEntry(self, entry, documentId):
"""Take the entry provided and put it in the correct place
Expand Down Expand Up @@ -267,8 +269,7 @@ def _index_object(self, documentId, obj, threshold=None, attr=''):
raise
except Exception:
LOG.error('Should not happen: oldDatum was there, '
'now its not, for document: {0}'.format(
documentId))
'now its not, for document: %s', documentId)

if datum is not _marker:
self.insertForwardIndexEntry(datum, documentId)
Expand Down Expand Up @@ -324,7 +325,7 @@ def unindex_object(self, documentId):
raise
except Exception:
LOG.debug('Attempt to unindex nonexistent document'
' with id {0}'.format(documentId), exc_info=True)
' with id %s', documentId, exc_info=True)

def _apply_not(self, not_parm, resultset=None):
index = self._index
Expand Down Expand Up @@ -566,9 +567,9 @@ def query_index(self, record, resultset=None):
except TypeError:
# key is not valid for this Btree so the value is None
LOG.error(
'{context!s}: query_index tried '
'to look up key {key!r} from index {index!r} '
'but key was of the wrong type.'.format(
'%(context)s: query_index tried '
'to look up key %(key)r from index %(index)r '
'but key was of the wrong type.', dict(
context=self.__class__.__name__,
key=k,
index=self.id,
Expand Down
12 changes: 6 additions & 6 deletions src/Products/ZCatalog/Catalog.py
Expand Up @@ -164,8 +164,8 @@ def addColumn(self, name, default_value=None, threshold=10000):
if name != name.strip():
# Someone could have mistakenly added a space at the end
# of the input field.
LOG.warning("stripped space from new column %r -> %r", name,
name.strip())
LOG.warning('stripped space from new column %r -> %r', name,
name.strip())
name = name.strip()

if name in schema:
Expand Down Expand Up @@ -206,7 +206,7 @@ def delColumn(self, name, threshold=10000):

if name not in self.schema:
LOG.error('delColumn attempted to delete nonexistent '
'column %s.' % str(name))
'column %s.', str(name))
return

del names[_index]
Expand Down Expand Up @@ -254,7 +254,7 @@ def addIndex(self, name, index_type):
if name != name.strip():
# Someone could have mistakenly added a space at the end
# of the input field.
LOG.warning("stripped space from new index %r -> %r", name,
LOG.warning('stripped space from new index %r -> %r', name,
name.strip())
name = name.strip()

Expand Down Expand Up @@ -370,7 +370,7 @@ def catalogObject(self, object, uid, threshold=None, idxs=None,
total = total + blah
else:
LOG.error('catalogObject was passed bad index '
'object %s.' % str(x))
'object %s.', str(x))

return total

Expand Down Expand Up @@ -404,7 +404,7 @@ def uncatalogObject(self, uid):
else:
LOG.error('uncatalogObject unsuccessfully '
'attempted to uncatalog an object '
'with a uid of %s. ' % str(uid))
'with a uid of %s. ', str(uid))

def uniqueValuesFor(self, name):
""" return unique values for FieldIndex name """
Expand Down
4 changes: 2 additions & 2 deletions src/Products/ZCatalog/ZCatalog.py
Expand Up @@ -280,7 +280,7 @@ def refreshCatalog(self, clear=0, pghandler=None):
except ConflictError:
raise
except Exception:
LOG.error('Recataloging object at %s failed' % p,
LOG.error('Recataloging object at %s failed', p,
exc_info=sys.exc_info())

if pghandler:
Expand Down Expand Up @@ -429,7 +429,7 @@ def reindexIndex(self, name, REQUEST, pghandler=None):
obj = self.resolve_url(p, REQUEST)
if obj is None:
LOG.error('reindexIndex could not resolve '
'an object from the uid %r.' % p)
'an object from the uid %r.', p)
else:
# don't update metadata when only reindexing a single
# index via the UI
Expand Down

0 comments on commit 3b2504d

Please sign in to comment.