本文摘自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中的条件判断语句基础学习
Python输出2到100之间的素数
Python字典怎么排序
Python支持返回函数的实例解析
Python 怎么调用百度地图api
Python统计字符串中数字个数
Python中的%是什么意思
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python如何记录调用堆栈日志实现方法?