utils.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:montage 作者: storyful 项目源码 文件源码
def log_sql_queries_to_console(path):
    """
        Logs SQL queries to terminal if in debug mode.
        We need to import connection at runtime as this is
        used in the wsgi handlers for the API endpoints and
        django settings are not available at import time there.
    """
    from django.db import connection
    if settings.DEBUG and len(connection.queries) > 0:
        total_time = 0
        output = "\033[1;31m[Request Started: %s]\033[0m\n" % (path)
        for query in connection.queries:
            total_time += float(query.get('time'))
            output = output + "\033[1;31m[%s]\033[0m \033[1m%s\033[0m\n" % (
                query.get('time'), " ".join(query['sql'].split()))
        output = output + "\033[1;31m[Request Finished: %s queries in %s seconds] \
        \033[0m" % (len(connection.queries), total_time)
        print output.encode('utf-8')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号