gpt4 book ai didi

python - 如何在 GAE Python logging.info 日志中包含文件名和行号?

转载 作者:太空狗 更新时间:2023-10-30 01:33:56 25 4
gpt4 key购买 nike

在日志中,时间戳可用,但“源文件名”“行号” 并未随每条日志消息一起记录。

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

“源文件名” 是指生成日志的 Python 代码文件 (*.py)。

最佳答案

在你的 main.py 添加:

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

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

关于python - 如何在 GAE Python logging.info 日志中包含文件名和行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27456005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com