feature request: query logging
I could not find any issue/question/pr related to this, so I'm starting a new one.
It would be great to have query logging implemented inside asyncpg:
- to see all executed queries and their parameters
- especially nice would be to have a query cache logging to see cache hits/misses
Not a bad idea. Patches are welcome.
Are there any performance tests in the repo?
Could you please have a look at changes while I'm fixing and writing new tests?
@elprans any updates guys?
It's possible to implement this oneself!
import logging
from asyncpg.connection import Connection
class LoggingConnection(Connection):
_query_logger = logging.getLogger(__name__)
async def _execute(self, query, args, *posargs, **kwargs):
self._query_logger.info(
f"Executing query:\n" +
'\n'.join(' ' + line for line in query.splitlines()) +
f"...with args: {args}")
return await Connection._execute(self, query, args, *posargs, **kwargs)
Now just pass ConnectionLogger as the connection_class parameter of asyncpg.create_pool.
Implemented in #1043.