I need to know how I can log an exception stack trace along with the method arguments' actual values.
To clarify my requirement, please refer to following example:
Code Sample
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)
Actual Stack trace in 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!
Required Stack trace in 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!
If you looked carefully in the Required Stack trace in Python section, I have replaced the evaluated values of method arguments in stack trace.
I hope this example gives clear perspective of my requirements