sqlalchemy is keep loggin to console even I have the following code
import logging
logger = logging.getLogger()
logger.disabled = True
How to turn off sqlalchemy's logging completely?
sqlalchemy is keep loggin to console even I have the following code
import logging
logger = logging.getLogger()
logger.disabled = True
How to turn off sqlalchemy's logging completely?
Did you pass echo=True
to create_engine()
? By default it creates StreamHandler which outputs to console. As documentation says, if you didn't provide any echo=True
arguments and didn't configure root sqlalchemy
logger, it will not log anything.
SQLALCHEMY_ECHO
env var in flask config –
Apollinaire You can turn off the sqlalchemy
logger using:
import logging
logging.basicConfig()
logging.getLogger('sqlalchemy').setLevel(logging.ERROR)
For more info, see the docs.
echo=False
to all functions that may ever create an engine. –
Demandant logging.getLogger('sqlalchemy.engine')
to logging.getLogger('sqlalchemy')
, which should cover more cases. Other than that, don't know why it wouldn't work... –
Demandant /usr/lib64/python2.7/site-packages/sqlalchemy/engine/default.py:450: Warning: Duplicate entry 'some-key-duplicate' for key 'title' cursor.execute(statement, parameters)
–
Turpentine statement
query. Maybe you're trying to insert into the same column multiple times or something.. –
Demandant Charset
= 'utf8' and Collation
= 'utf8_bin' –
Sachet A more drastic solution:
import logging
logging.disable(logging.WARNING)
logging.disable(logging.INFO)
–
Certain app.py
file. –
Repast The most complete solution:
sqlalchemy.engine.Engine
does something weird (with log levels?), so while logging.getLogger('sqlalchemy.engine.Engine').setLevel(logging.ERROR)
doesn't work, logging.disable(logging.ERROR)
still can.
Combining the specificity and the method, I managed to disable it with:
logging.getLogger('sqlalchemy.engine.Engine').disabled = True
There. It actually works, and without breaking other or all loggers in the process like some other responses here.
python:3.11-slim
image. –
Mountbatten © 2022 - 2024 — McMap. All rights reserved.