[英]How to have file name and line number in GAE Python logging.info logs?
在日志中,時間戳可用,但每個日志消息都不記錄"source file name"
和"line number"
。
如何在GAE Python logging.info
(或logging.warn
或logging.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.