How to turn sqlalchemy logging off completely

Question:

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?

Asked By: pythoniku

||

Answers:

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.

Answered By: Palasaty

You can turn off the sqlalchemy logger using:

import logging

logging.basicConfig()
logging.getLogger('sqlalchemy').setLevel(logging.ERROR)

For more info, see the docs.

Answered By: ostrokach

A more drastic solution:

import logging

logging.disable(logging.WARNING)
Answered By: Takamura
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.