List Info

Thread: SQLAlchemy logging in paster shell




SQLAlchemy logging in paster shell
country flaguser name
Germany
2007-12-16 07:36:14
Dear list...

I've struggling with logging of SQL statements through
SQLAlchemy for
months now. I start to assume that logging is somehow broken
in the
paster shell.

My development.ini has the default [loggers] section as part
of the
0.9.6.1 Pylons template. I have just tried to add an
SQLAlchemy logger
like this:

    [loggers]
    keys = root,sqlalchemy

    [logger_sqlalchemy]
    level = DEBUG
    handlers = sqlalchemy
    qualname = sqlalchemy.engine
    propagate = 1

    [handler_sqlalchemy]
    class = StreamHandler
    args = (sys.stderr,)
    level = DEBUG
    formatter = generic

I am no logging God but this should do some logging
according to
http://www.sqlalchemy.org/docs/04/dbengine.html
#dbengine_logging. And
the SQLAlchemy docs say that I should rather not use
"sqlalchemy.echo=True" because it would interfere
with the logging
through the "sqlalchemy.engine" logger. So I left
"echo" to False.

This logging works for all requests done from the web.
However it does
not work through a "paster shell" session. The
only way I could get
logging working there was setting

    g.sa_engine.logger.disabled = 0

which somehow seems to be set to 1 by default (credits to
Steven Holmes
on IRC). And you have to set "echo" to True. This
isn't very sane.

Interesting though that even websetup.py is logging SQL
output properly.
My websetup.py looks like this:

    """Setup the foobar
application"""
    import logging

    from paste.deploy import appconfig
    from pylons import config

    from foobar.config.environment import load_environment

    log = logging.getLogger(__name__)

    def setup_config(command, filename, section, vars):
        """Place any commands to setup foobar
here"""
        conf = appconfig('config:' + filename)
        load_environment(conf.global_conf, conf.local_conf)

        from foobar import model
        log.info("Creating tables")
       
model.metadata.create_all(bind=config['pylons.g'].sa_engine)

        log.info("Successfully setup")

Drives me mad to be stuck here. After all SQLAlchemy is
often doing
things I don't intend. Of course that's my own fault and
misconfiguration but the paster-shell is the easiest way to
find out.
Currently I abuse the online debugger for that purpose. :(

What's wrong with paster shell?

Cheers
 Christoph


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-discussgooglegroups.com
To unsubscribe from this group, send email to
pylons-discuss-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )