On Feb 28, 2010, at 11:21 AM, Manlio Perillo wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I would like to write a patch for ticket #877.
> 
> What is the best method to implement the requested feature?
> 
> The ExecutionContext class has a post_exec method, so the implementation
> for the psycopg2 driver can override this method, check for the notice
> messages and log them.
> 
> Attached is a very simple patch.
> 
> The problem is that NOTICE messages will only be logged if echo
> parameter is set to True, in the create_engine function; however I
> usually don't want to echo all SQL statatements, but I'm interested to
> see NOTICE messages.

1. dont use the engine's logger, use one specific to the psycopg2 dialect
2. if the logger has info enabled, then you can dump the notices.  otherwise 
don't waste CPU digging through them

put it under the namespace logging.getLogger('sqlalchemy.dialects.postgresql') .




> 
> 
> By the way, it seems there is a bug in the documentation:
> http://www.sqlalchemy.org/docs/reference/sqlalchemy/connections.html?highlight=create_engine#sqlalchemy.create_engine
> 
> """echo=False – if True, the Engine will log all statements as well as a
> repr() of their parameter lists to the engines logger, which defaults to
> sys.stdout. The echo attribute of Engine can be modified at any time to
> turn logging on and off. If set to the string "debug", result rows will
> be printed to the standard output as well. This flag ultimately controls
> a Python logger; see dbengine_logging at the end of this chapter for
> information on how to configure logging directly."""
> 
> However there is no dbengine_logging section!
> 
> 
> 
> Thanks  Manlio
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iEYEARECAAYFAkuKmCEACgkQscQJ24LbaURdJgCeIPIbeYfVK+9B0cQK0Bv2YhBt
> epQAnj44OYf66Kug6zZvRQd5SmzxE1Vv
> =Rlnm
> -----END PGP SIGNATURE-----
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 
> diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py 
> b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
> --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py
> +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
> @@ -135,6 +135,10 @@
>         else:
>             return base.ResultProxy(self)
> 
> +    def post_exec(self):
> +        for notice in self._connection.connection.notices:
> +            self.engine.logger.info(notice)
> +
> 
> class PostgreSQL_psycopg2Compiler(PGCompiler):
>     def visit_mod(self, binary, **kw):

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to