From 65f5887e9a824ee1b50592325fd9f6cf6d1639f8 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 9 Jun 2013 16:16:53 -0400 Subject: [PATCH] Added pool logging for "rollback-on-return" and the less used "commit-on-return". This is enabled with the rest of pool "debug" logging. [ticket:2752] --- doc/build/changelog/changelog_09.rst | 8 ++++++++ lib/sqlalchemy/pool.py | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 4d344a13d5..f1d0bcc926 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -6,6 +6,14 @@ .. changelog:: :version: 0.9.0 + .. change:: + :tags: feature, pool + :tickets: 2752 + + Added pool logging for "rollback-on-return" and the less used + "commit-on-return". This is enabled with the rest of pool + "debug" logging. + .. change:: :tags: bug, mysql :tickets: 2715 diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index 0470e9e485..ade1e90ceb 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -193,8 +193,8 @@ class Pool(log.Identified): except (SystemExit, KeyboardInterrupt): raise except: - self.logger.debug("Exception closing connection %r", - connection) + self.logger.error("Exception closing connection %r", + connection, exc_info=True) @util.deprecated( 2.7, "Pool.add_listener is deprecated. Use event.listen()") @@ -381,12 +381,22 @@ def _finalize_fairy(connection, connection_record, pool, ref, echo): return if connection is not None: + if connection_record and echo: + pool.logger.debug("Connection %r being returned to pool", + connection) + try: if pool.dispatch.reset: pool.dispatch.reset(connection, connection_record) if pool._reset_on_return is reset_rollback: + if echo: + pool.logger.debug("Connection %s rollback-on-return", + connection) pool._dialect.do_rollback(connection) elif pool._reset_on_return is reset_commit: + if echo: + pool.logger.debug("Conneciton %s commit-on-return", + connection) pool._dialect.do_commit(connection) # Immediately close detached instances if connection_record is None: @@ -399,9 +409,6 @@ def _finalize_fairy(connection, connection_record, pool, ref, echo): if connection_record is not None: connection_record.fairy = None - if echo: - pool.logger.debug("Connection %r being returned to pool", - connection) if connection_record.finalize_callback: connection_record.finalize_callback(connection) del connection_record.finalize_callback @@ -436,7 +443,7 @@ class _ConnectionFairy(object): self._connection_record = None raise if self._echo: - self._pool.logger.debug("Connection %r checked out from pool" % + self._pool.logger.debug("Connection %r checked out from pool", self.connection) @property -- 2.47.3