Issues

Issue #2837 new

fix logging to truncate large textual/binary values

Anonymous created an issue

(original reporter: jonathan) The FAQ on logging

 http://docs.sqlalchemy.org/en/rel_0_8/faq.html?highlight=logging#how-do-i-configure-logging

sent me to the Engine logging docs:

   http://docs.sqlalchemy.org/en/rel_0_8/core/engines.html#dbengine-logging

I wanted to suggest this addition to the docs :


Sometimes you might want to disable existing query logging for certain statements, such as when you are inserting a BLOB or large TEXT value.

An easy way to accomplish this is to wrap your query in a pair of statements that toggle the disabled attribute of the logger.

In the example below, note that the logger needed to disable already-enabled query logging is sqlalchemy.engine.base.Engine , and not the sqlalchemy.engine logger mentioned above.

import logging
logging.getLogger('sqlalchemy.engine.base.Engine').disabled = True
... execute query ...
logging.getLogger('sqlalchemy.engine.base.Engine').disabled = False

Comments (9)

  1. Mike Bayer repo owner

    why don't we fix logging not to log out the full expanse of long binary/text fields ? we've already made similar enhancements long ago regarding long parameter sets.

    the doc suggestion is a little bit of a very specific recipe.

  2. Anonymous

    (original author: jonathan) Limiting the size of these fields logging is a much better idea.

    It took me a while to dig out this general approach, and it seemed like a natural "need" by the current system... and also not in-line with the current docs. ( I did not expect the logger path to be different like that, though it does make sense ).

    My dev box uses SqlAlchemy as the message broker for Celery Resizing (it's handled by Redis on Production ). All of the sudden during some tests, I'm starting to see a 1.9MB jpeg converted into b64 and piped into an INSERT statement on sqlalchemy. Not fun.

  3. Log in to comment