Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress sqlalchemy.engine.base.Engine logging to stdout?

I am running an python app in Windows 7 which uses sqlalchemy.

In the console (DOS prompt) I can see a lot of output from the sqlalchemy module e.g.

2013-09-16 13:59:20,158 INFO sqlalchemy.engine.base.Engine UPDATE DATA SET qty=?, price=?

I want to continue to log these messages in the log file but would like to suppress them from printing to the stdout.

like image 995
Anthony Kong Avatar asked Dec 26 '22 20:12

Anthony Kong


1 Answers

Try adding a FileHandler to the sqlalchemy logger and setting its propagate attribute to False, for example like this:

import logging

sqla_logger = logging.getLogger('sqlalchemy')
sqla_logger.propagate = False
sqla_logger.addHandler(logging.FileHandler('/path/to/sqla.log'))

Alternatively you can use a logging configuration API (e.g. logging.config.dictConfig()) to do the same thing as above.

like image 184
Vinay Sajip Avatar answered Jan 13 '23 16:01

Vinay Sajip