Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: query logging #629

Closed
dmig-alarstudios opened this issue Sep 30, 2020 · 6 comments
Closed

feature request: query logging #629

dmig-alarstudios opened this issue Sep 30, 2020 · 6 comments

Comments

@dmig-alarstudios
Copy link

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
@elprans
Copy link
Member

elprans commented Sep 30, 2020

Not a bad idea. Patches are welcome.

@dmig
Copy link

dmig commented Oct 1, 2020

Are there any performance tests in the repo?

@dmig-alarstudios
Copy link
Author

Could you please have a look at changes while I'm fixing and writing new tests?

@maksimartemevalar
Copy link

@elprans
any updates guys?

@bayersglassey-zesty
Copy link

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.

@elprans
Copy link
Member

elprans commented Oct 9, 2023

Implemented in #1043.

@elprans elprans closed this as completed Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants