日志记录不显示数组的结果 [英] logging does not show the result of array

查看:112
本文介绍了日志记录不显示数组的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • Django 1.9

  • Python 3.4

我的views.py中有以下Django代码

I have the following Django code in my views.py

from django.db import connection
    cursor = connection.cursor()
    cursor.execute('SELECT p.name, p.name_zh_hans, p.art_number, ....')
    rows = cursor.fetchall()

logger = logging.getLogger(__name__)

for row in rows:
        row_num += 1
        logger.info(row)
        for col_num in range(len(row)):
            ws.write(row_num, col_num, row[col_num], font_style)



我在日志文件中有什么?



What did I get inside the log file?

(0.005) SELECT p.name, p.name_zh_hans, p.art_number, ....; args=None
(0.005) SELECT p.name, p.name_zh_hans, p.art_number, ....; args=None
(0.006) SELECT p.name, p.name_zh_hans, p.art_number, ....; args=None



我期待什么?



显示日志文件内的数组内容

What did I expect?

Display of the array contents inside the log file

出了什么问题?

推荐答案

我相信你所看到的实际上是来自 django.db.backends 的日志,结帐此引用

I belive that what you are seeing are actually logs from django.db.backends, checkout this reference.


与代码与数据库的交互相关的消息。对于
示例,请求
执行的每个应用程序级SQL语句都将在DEBUG级别记录到此记录器。

Messages relating to the interaction of code with the database. For example, every application-level SQL statement executed by a request is logged at the DEBUG level to this logger.

此记录器的消息具有以下额外的上下文:

Messages to this logger have the following extra context:

持续时间:执行SQL语句所需的时间。

sql :执行的SQL
语句。
params :在
中用于SQL调用的参数。

出于性能原因,无论日志记录级别或
处理程序的安装情况如何,将settings.DEBUG设置为True时,只能启用SQL日志记录

duration: The time taken to execute the SQL statement.
sql: The SQL statement that was executed.
params: The parameters that were used in the SQL call.

For performance reasons, SQL logging is only enabled when settings.DEBUG is set to True, regardless of the logging level or handlers that are installed.

此日志记录不包括框架级初始化(例如SET
TIMEZONE)或事务管理查询(例如BEGIN,COMMIT和
ROLLBACK)。如果您想查看
所有数据库查询,请打开数据库中的查询记录。

This logging does not include framework-level initialization (e.g. SET TIMEZONE) or transaction management queries (e.g. BEGIN, COMMIT, and ROLLBACK). Turn on query logging in your database if you wish to view all database queries.

您正在记录级别日志级别信息同时 django.db.backends 日志在 DEBUG 级别,以便检出您的日志处理程序,以确保您实际上记录了什么以及您的不是:)

You are logging with level log level info meanwhile django.db.backends logs at DEBUG level so checkout also your log handlers to be sure what you are actually logging and what you are not :)

希望它有帮助!

这篇关于日志记录不显示数组的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆