Skip to content

feature request: query logging #629

Closed

Description

@dmig-alarstudios

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

Activity

  1. elprans commented on Sep 30, 2020

    @elprans
    Member

    Not a bad idea. Patches are welcome.

  2. dmig commented on Oct 1, 2020

    @dmig

    Are there any performance tests in the repo?

  3. dmig-alarstudios commented on Oct 1, 2020

    @dmig-alarstudios
    Author

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

  4. maksimartemevalar commented on May 11, 2022

    @maksimartemevalar

    @elprans
    any updates guys?

  5. bayersglassey-zesty commented on Mar 7, 2023

    @bayersglassey-zesty

    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.

  6. elprans commented on Oct 9, 2023

    @elprans
    Member

    Implemented in #1043.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions