本文整理匯總了Python中flask_sqlalchemy.get_debug_queries方法的典型用法代碼示例。如果您正苦於以下問題:Python flask_sqlalchemy.get_debug_queries方法的具體用法?Python flask_sqlalchemy.get_debug_queries怎麽用?Python flask_sqlalchemy.get_debug_queries使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flask_sqlalchemy
的用法示例。
在下文中一共展示了flask_sqlalchemy.get_debug_queries方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: log_slow_queries
# 需要導入模塊: import flask_sqlalchemy [as 別名]
# 或者: from flask_sqlalchemy import get_debug_queries [as 別名]
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
示例2: after_request
# 需要導入模塊: import flask_sqlalchemy [as 別名]
# 或者: from flask_sqlalchemy import get_debug_queries [as 別名]
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
示例3: after_request
# 需要導入模塊: import flask_sqlalchemy [as 別名]
# 或者: from flask_sqlalchemy import get_debug_queries [as 別名]
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
示例4: get_num_queries
# 需要導入模塊: import flask_sqlalchemy [as 別名]
# 或者: from flask_sqlalchemy import get_debug_queries [as 別名]
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
示例5: test_lbheartbeat_makes_no_db_queries
# 需要導入模塊: import flask_sqlalchemy [as 別名]
# 或者: from flask_sqlalchemy import get_debug_queries [as 別名]
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
示例6: after_request
# 需要導入模塊: import flask_sqlalchemy [as 別名]
# 或者: from flask_sqlalchemy import get_debug_queries [as 別名]
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
示例7: after_request
# 需要導入模塊: import flask_sqlalchemy [as 別名]
# 或者: from flask_sqlalchemy import get_debug_queries [as 別名]
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