SqlAlchemy logging FAQ

46 views
Skip to first unread message

Kent

unread,
Aug 17, 2010, 11:45:50 AM8/17/10
to sqlalchemy
The logging FAQ states "Therefore, when using Python logging, ensure
all echo flags are set to False at all times, to avoid getting
duplicate log lines."
http://www.sqlalchemy.org/docs/dbengine.html#configuring-logging

Is this no longer correct information?

I am using turbogears (which creates the engine with
engine_from_config()) and with the config file like this:

sqlalchemy.echo = false
sqlalchemy.echo_pool = false
sqlalchemy.pool_recycle = 3600

I cannot get engine logging no matter what I put in the logging config
file. echo is turned off and sqlalchemy won't even hit the
logger.debug() method.

If I try:

sqlalchemy.echo = true

then I cannot get DEBUG level no matter what level is specified in the
logging config file (but can get INFO)

If I try:
sqlalchemy.echo = debug

I get this:
File "/home/rarch/tg2env/lib/python2.6/site-packages/
TurboGears2-2.0.1.1kb-py2.6.egg/tg/configuration.py", line 390, in
setup_sqlalchemy
engine = engine_from_config(pylons_config, 'sqlalchemy.')
File "/home/rarch/tg2env/lib/python2.6/site-packages/
SQLAlchemy-0.6.3.2dev-py2.6-linux-x86_64.egg/sqlalchemy/engine/
__init__.py", line 259, in engine_from_config
opts = _coerce_config(configuration, prefix)
File "/home/rarch/tg2env/lib/python2.6/site-packages/
SQLAlchemy-0.6.3.2dev-py2.6-linux-x86_64.egg/sqlalchemy/engine/
__init__.py", line 280, in _coerce_config
util.coerce_kw_type(options, option, type_)
File "/home/rarch/tg2env/lib/python2.6/site-packages/
SQLAlchemy-0.6.3.2dev-py2.6-linux-x86_64.egg/sqlalchemy/util.py", line
562, in coerce_kw_type
kw[key] = asbool(kw[key])
File "/home/rarch/tg2env/lib/python2.6/site-packages/
SQLAlchemy-0.6.3.2dev-py2.6-linux-x86_64.egg/sqlalchemy/util.py", line
551, in asbool
raise ValueError("String is not true/false: %r" % obj)
ValueError: String is not true/false: 'debug'


**** by the way, that seems like a bug. If 'debug' is allowed for
echo, then why is asbool() invoked?


The only way I could get this to work is by commenting out the echo
specification entirely:
#sqlalchemy.echo =
sqlalchemy.echo_pool = false
sqlalchemy.pool_recycle = 3600

Only now can the logging config sections have a chance to set the
logging level to DEBUG or INFO.

Michael Bayer

unread,
Aug 18, 2010, 10:58:20 AM8/18/10
to sqlal...@googlegroups.com

On Aug 17, 2010, at 11:45 AM, Kent wrote:

> The logging FAQ states "Therefore, when using Python logging, ensure
> all echo flags are set to False at all times, to avoid getting
> duplicate log lines."
> http://www.sqlalchemy.org/docs/dbengine.html#configuring-logging
>
> Is this no longer correct information?

it is correct


>
> I am using turbogears (which creates the engine with
> engine_from_config()) and with the config file like this:
>
> sqlalchemy.echo = false
> sqlalchemy.echo_pool = false
> sqlalchemy.pool_recycle = 3600
>
> I cannot get engine logging no matter what I put in the logging config
> file. echo is turned off and sqlalchemy won't even hit the
> logger.debug() method.

assuming you're on the pylons version of turbogears, you leave the echo flags alone. You configure logging in the [logging] section of your .ini file, using loggers and log levels. I use Pylons and this all works very well.


Kent Bower

unread,
Aug 18, 2010, 11:05:29 AM8/18/10
to sqlal...@googlegroups.com
Ah. Then the problem is in turbogears (which creates a default .ini
file with):

================================
#echo shouldn't be used together with the logging module.


sqlalchemy.echo = false
sqlalchemy.echo_pool = false
sqlalchemy.pool_recycle = 3600

...logging sections...

================================

Instead, its default .ini file should leave the flag alone.

I've directed TG group to this thread, thanks for your help.

Reply all
Reply to author
Forward
0 new messages