I want to build a tool that I can invoke when rolling out new code for testing that will capture and evaluate all of the lines of execution and print them to a file so that it can be traced and debugged long after execution has finished. Think of this as a debugger that evaluates the return of every line of code and prints that line of code plus the return values of that line in another column, as it is also running the code. For example:
Timestamp File-Line Source Code Debug Watcher
---------------- --------- ------------------------------- -----------------
20130109-10:18AM test.py-1 import mathy
20130109-10:18AM test.py-2 x = 1 # inline comments return: x:1
20130109-10:18AM test.py-3 ans = divide(x,2) call: math_functions.py-55:divide(dividend:1, divisor:2)
20130109-10:18AM mathy.py-56 return divedend / divisor divide() function return: 0.5
20130109-10:18AM test.py-4 print "Got %d"%ans call: print : "Got 0.5"
etc...
Do you see how you can follow execution as it moves through separate functions, files, etc? This has the potential to generate a ton of log data, so it could be clipped to some limit size. I also have to punt on large data structures, such as dicts, arrays, etc. and create some special cases to handle those kinds of things.
I have created something like this before using traceback, but it never worked exactly right. Just wondering if something more polished might already exists. If not, how would you do it? Thanks.