Python flask_sqlalchemy.get_debug_queries() Examples
The following are 7
code examples of flask_sqlalchemy.get_debug_queries().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_sqlalchemy
, or try the search function
.
Example #1
Source File: utils.py From flask-shop with BSD 3-Clause "New" or "Revised" License | 7 votes |
def log_slow_queries(app): formatter = logging.Formatter( "[%(asctime)s]{%(pathname)s:%(lineno)d}\n%(levelname)s - %(message)s" ) handler = RotatingFileHandler( "slow_queries.log", maxBytes=10_000_000, backupCount=10 ) handler.setLevel(logging.WARN) handler.setFormatter(formatter) app.logger.addHandler(handler) @app.after_request def after_request(response): for query in get_debug_queries(): if query.duration >= app.config["DATABASE_QUERY_TIMEOUT"]: app.logger.warn( f"Context: {query.context}\n" f"SLOW QUERY: {query.statement}\n" f"Parameters: {query.parameters}\n" f"Duration: {query.duration}" ) return response
Example #2
Source File: views.py From circleci-demo-python-flask with MIT License | 5 votes |
def after_request(response): for query in get_debug_queries(): if query.duration >= current_app.config['CIRCULATE_SLOW_DB_QUERY_TIME']: current_app.logger.warning( 'Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context)) return response
Example #3
Source File: views.py From Flashcards with MIT License | 5 votes |
def after_request(response): for query in get_debug_queries(): if query.duration >= current_app.config['FLASHCARD_SLOW_DB_QUERY_TIME']: current_app.logger.warning( 'Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context)) return response
Example #4
Source File: test_utils.py From flask-security with MIT License | 5 votes |
def get_num_queries(datastore): """ Return # of queries executed during test. return None if datastore doesn't support this. """ if is_sqlalchemy(datastore): from flask_sqlalchemy import get_debug_queries return len(get_debug_queries()) return None
Example #5
Source File: test_flask.py From python-dockerflow with Mozilla Public License 2.0 | 5 votes |
def test_lbheartbeat_makes_no_db_queries(dockerflow, app): assert len(get_debug_queries()) == 0 response = app.test_client().get("/__lbheartbeat__") assert response.status_code == 200 assert len(get_debug_queries()) == 0
Example #6
Source File: logger_slow_query.py From web_develop with GNU General Public License v3.0 | 5 votes |
def after_request(response): for query in get_debug_queries(): if query.duration >= app.config['DATABASE_QUERY_TIMEOUT']: app.logger.warn( ('\nContext:{}\nSLOW QUERY: {}\nParameters: {}\n' 'Duration: {}\n').format(query.context, query.statement, query.parameters, query.duration)) return response
Example #7
Source File: views.py From flasky-first-edition with MIT License | 5 votes |
def after_request(response): for query in get_debug_queries(): if query.duration >= current_app.config['FLASKY_SLOW_DB_QUERY_TIME']: current_app.logger.warning( 'Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context)) return response