繁体   English   中英

如何在GAE Python logging.info日志中获取文件名和行号?

[英]How to have file name and line number in GAE Python logging.info logs?

在日志中,时间戳可用,但每个日志消息都不记录"source file name""line number"

如何在GAE Python logging.info (或logging.warnlogging.error等)中记录文件名和行号?

"source file name"是指生成日志的Python代码文件(* .py)。

在你的main.py添加:

formatter = logging.Formatter('%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s] %(message)s')

logging.getLogger().handlers[0].setFormatter(formatter)

您是否尝试过查看记录格式化程序

看起来应该是这样的

formatter = logging.Formatter(
    '[%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d}'
    ' %(levelname)s - %(message)s','%m-%d %H:%M:%S')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM