Skip to content

Commit

Permalink
s/logger/query_logger/, report BaseException too
Browse files Browse the repository at this point in the history
  • Loading branch information
elprans committed Oct 9, 2023
1 parent 3d2924a commit f59af17
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions asyncpg/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ async def _execute(
return result

@contextlib.contextmanager
def logger(self, callback):
def query_logger(self, callback):
"""Context manager that adds `callback` to the list of query loggers,
and removes it upon exit.
Expand All @@ -1822,15 +1822,15 @@ def __init__(self):
self.queries = []
def __call__(self, record):
self.queries.append(record.query)
>>> with con.logger(QuerySaver()) as log:
>>> with con.query_logger(QuerySaver()):
>>> await con.execute("SELECT 1")
>>> print(log.queries)
['SELECT 1']
.. versionadded:: 0.29.0
"""
self.add_query_logger(callback)
yield callback
yield
self.remove_query_logger(callback)

@contextlib.contextmanager
Expand All @@ -1839,7 +1839,7 @@ def _time_and_log(self, query, args, timeout):
exception = None
try:
yield
except Exception as ex:
except BaseException as ex:
exception = ex
raise
finally:
Expand Down

0 comments on commit f59af17

Please sign in to comment.