本文摘自php中文网,作者伊谢尔伦,侵删。
这篇文章主要介绍了Python记录详细调用堆栈日志的方法,涉及Python调用堆栈日志的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下本文实例讲述了Python记录详细调用堆栈日志的方法。分享给大家供大家参考。具体实现方法如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import sys
import os
def detailtrace(info):
retStr = ""
curindex = 0
f = sys._getframe()
f = f.f_back
while hasattr (f, "f_code" ):
co = f.f_code
retStr = "%s(%s:%s)->" % (os.path.basename(co.co_filename),
co.co_name,
f.f_lineno) + retStr
f = f.f_back
print retStr + info
def foo():
detailtrace( "hello world" )
def bar():
foo()
def main():
bar()
if name = = "main" :
main()
|
输出:
aaa1.py(<module>:27)->aaa1.py(main:24)->aaa1.py(bar:21)->aaa1.py(foo:18)->hello world
以上就是Python如何记录调用堆栈日志实现方法?的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python压缩包怎么安装
如何在线运行Python
Python操作表格添加行
Python中split是什么意思
Python中next和send的用法介绍(代码)
在windows中设置Python环境变量的实例讲解
Python怎么读写excel
Python注释用什么符号
Python如何利用lxml对xml进行读写操作教程
人工智能为什么用Python
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python如何记录调用堆栈日志实现方法?