From: Daniele Varrazzo Date: Tue, 29 Apr 2025 16:15:19 +0000 (+0200) Subject: chore: add connection debugging log in the C extension too X-Git-Tag: 3.2.7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62cd04d9cfef6c89791f51d40973ab190a6c2de9;p=thirdparty%2Fpsycopg.git chore: add connection debugging log in the C extension too --- diff --git a/psycopg/psycopg/generators.py b/psycopg/psycopg/generators.py index bf4f03486..d9b9858f1 100644 --- a/psycopg/psycopg/generators.py +++ b/psycopg/psycopg/generators.py @@ -56,7 +56,7 @@ READY_R = Ready.R READY_W = Ready.W READY_RW = Ready.RW -logger = logging.getLogger(__name__) +logger = logging.getLogger("psycopg") def _connect(conninfo: str, *, timeout: float = 0.0) -> PQGenConn[PGconn]: @@ -70,6 +70,7 @@ def _connect(conninfo: str, *, timeout: float = 0.0) -> PQGenConn[PGconn]: # $ PSYCOPG_IMPL=python python # >>> import logging # >>> logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s') + # >>> logging.getLogger("psycopg").setLevel(logging.DEBUG) conn = pq.PGconn.connect_start(conninfo.encode()) logger.debug("connection started: %s", conn) diff --git a/psycopg_c/psycopg_c/_psycopg/generators.pyx b/psycopg_c/psycopg_c/_psycopg/generators.pyx index 594db0881..f85c821c4 100644 --- a/psycopg_c/psycopg_c/_psycopg/generators.pyx +++ b/psycopg_c/psycopg_c/_psycopg/generators.pyx @@ -42,6 +42,7 @@ def connect(conninfo: str, *, timeout: float = 0.0) -> PQGenConn[abc.PGconn]: if timeout: deadline = monotonic() + timeout + logger.debug("connection started: %s", conn) while True: if conn_status == libpq.CONNECTION_BAD: encoding = conninfo_encoding(conninfo) @@ -52,6 +53,7 @@ def connect(conninfo: str, *, timeout: float = 0.0) -> PQGenConn[abc.PGconn]: with nogil: poll_status = libpq.PQconnectPoll(pgconn_ptr) + logger.debug("connection polled: %s", conn) if poll_status == libpq.PGRES_POLLING_READING \ or poll_status == libpq.PGRES_POLLING_WRITING: