1. Michael Bayer
  2. sqlalchemy
  3. Issues


Issue #2837 resolved

fix logging to truncate large textual/binary values

Anonymous created an issue

(original reporter: jonathan) The FAQ on logging


sent me to the Engine logging docs:


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 (10)

  1. Michael 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. Michael Bayer repo owner
    • All string formatting of bound parameter sets and result rows for logging, exception, and repr() purposes now truncate very large scalar values within each collection, including an "N characters truncated" notation, similar to how the display for large multiple-parameter sets are themselves truncated. fixes #2837

    → <<cset 591e0cf08a79>>

  4. Log in to comment