db: logging option for cursor
In some cases we expect query to fail (LOCK NOWAIT) but it still clutters the logs. Option for not logging cursor-level errors. Fixes: https://pagure.io/koji/issue/2837
This commit is contained in:
parent
bc04708990
commit
e7db7d8b53
3 changed files with 10 additions and 6 deletions
|
|
@ -132,7 +132,7 @@ class CursorWrapper:
|
|||
params[i] = tuple(item)
|
||||
return sql, params
|
||||
|
||||
def execute(self, operation, parameters=()):
|
||||
def execute(self, operation, parameters=(), log=True):
|
||||
debug = self.logger.isEnabledFor(logging.DEBUG)
|
||||
operation, parameters = self.preformat(operation, parameters)
|
||||
if debug:
|
||||
|
|
@ -141,7 +141,8 @@ class CursorWrapper:
|
|||
try:
|
||||
ret = self.cursor.execute(operation, parameters)
|
||||
except Exception:
|
||||
self.logger.error('Query failed. Query was: %s', self.quote(operation, parameters))
|
||||
if log:
|
||||
self.logger.error('Query failed. Query was: %s', self.quote(operation, parameters))
|
||||
raise
|
||||
if debug:
|
||||
self.logger.debug("Execute operation completed in %.4f seconds", time.time() - start)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue