我需要知道如何记录异常堆栈跟踪以及方法参数的实际值。
为了澄清我的要求,请参考以下示例:
代码示例
import logging
def a(str, str2):
print str + str2
raise Exception("Custom err ==> " + str + "----" + str2)
def b(str):
a(str, "World!")
def c(str):
b(str)
try:
val = 'Hello' #Let's say this value is coming from DB
c(val)
except:
logging.exception("err", exc_info=True)
Python 中的实际堆栈跟踪
HelloWorld!
ERROR:root:err
Traceback (most recent call last):
File "except.py", line 14, in <module>
c('Hello')
File "except.py", line 11, in c
b(str)
File "except.py", line 8, in b
a(str, "World!")
File "except.py", line 5, in a
raise Exception("Custom err ==> " + str + "----" + str2)
Exception: Custom err ==> Hello----World!
Python中所需的堆栈跟踪
HelloWorld!
ERROR:root:err
Traceback (most recent call last):
File "except.py", line 14, in <module>
c('Hello')
File "except.py", line 11, in c
b('Hello')
File "except.py", line 8, in b
a('Hello', "World!")
File "except.py", line 5, in a
raise Exception("Custom err ==> " + str + "----" + str2)
Exception: Custom err ==> Hello----World!
如果您仔细查看Python 中所需的堆栈跟踪部分,我已经替换了堆栈跟踪中方法参数的评估值。
我希望这个例子能清楚地说明我的要求