當前位置: 首頁>>代碼示例>>Python>>正文


Python flask_sqlalchemy.get_debug_queries方法代碼示例

本文整理匯總了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 
開發者ID:hjlarry,項目名稱:flask-shop,代碼行數:24,代碼來源:utils.py

示例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 
開發者ID:CircleCI-Public,項目名稱:circleci-demo-python-flask,代碼行數:10,代碼來源:views.py

示例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 
開發者ID:KevDi,項目名稱:Flashcards,代碼行數:9,代碼來源:views.py

示例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 
開發者ID:Flask-Middleware,項目名稱:flask-security,代碼行數:11,代碼來源:test_utils.py

示例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 
開發者ID:mozilla-services,項目名稱:python-dockerflow,代碼行數:7,代碼來源:test_flask.py

示例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 
開發者ID:dongweiming,項目名稱:web_develop,代碼行數:10,代碼來源:logger_slow_query.py

示例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 
開發者ID:miguelgrinberg,項目名稱:flasky-first-edition,代碼行數:10,代碼來源:views.py


注:本文中的flask_sqlalchemy.get_debug_queries方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。