Flask SQLAlchemy display queries for debug

后端 未结 8 1234
感情败类
感情败类 2021-02-03 17:21

I am developing an app with flask and SQL Alchemy. I need to display the queries executed to generate a page alongside the time each query took for debugging

What\'s the

8条回答
  •  天涯浪人
    2021-02-03 17:52

    If you are using your own python logging configuration, you might want to simply set the level of the 'sqlalchemy.engine' logger to 'INFO' in your config.

    There are many ways of configuring your python logging, but here is an example using logging.config.dictConfig()

    import logging.config
    
    logging.config.dictConfig({
       ...
       'loggers': {
           'sqlalchemy.engine': {
               'level': 'INFO',
               'handlers': ...
           }
       }
    })
    

提交回复
热议问题