auto-debugging features?
Steven D. Arnold
stevena at permanent.cc
Sat Jun 3 20:00:33 EDT 2000
Hey folks,
Throwing this out for consideration and criticism.
I'd like a generic system-wide method of logging the activities of my
programs for debugging purposes. If I write and distribute a program, I'd
like to be able to allow the user to set the debug level to a variety of
different places, perhaps through an interface I provide, resulting in a
log of the program's activity that can be parsed by any program that can
use the debugging info protocol. The log would probably be in
human-readable text and would simply be parsed by a more sophisticated
program intended to help with reviewing the log information.
I'd like to get all this without cluttering up my code with print
statements, or worse yet, `if' statements, a la:
if (g_debuglevel > 5):
print "[NOTICE/reports.cell.print_cell] Called function \"print_cell\"
with params:"
Debugging info would go to stderr. The user could of course replace stderr
with an object of their choosing, resulting in an app that can
automatically transmit debugging info to any place on the network, for example.
Something that would be cool in such a debugging info utility:
- Notification on entry to a function.
- On entry to a function, list the parameters and values for the params.
- When data is changed, note the before and after values.
- When an if statement is executed, list the expressions that were
compared and the values of each.
It 'feels' to me that the most general way to solve this problem would be
to introduce a series of meta-magic functions in python that would trigger
when important events occured; but this would only happen if some kind of
flag were turned on. So, for example, a __func__ meta-magic method could
be triggered whenever any method in a class were called. Paramters to
__func__ would be the method name and the entire parameter list. The coder
of __func__ could determine exactly how the method would react to any
function being called -- anything from no action, to writing a line to a
log file, to sending a message to a network host.
Similarly, we might have a function for __data_to_change__, which would be
passed a stack trace, the value of the variable about to change and the
value to which it would be changed.
True, __getattr__ would handle some aspects of this, but I would prefer to
keep __getattr__ clean and oriented around a single purpose -- implementing
the class of which it is a part. This suite of meta-magic functions would
hopefully cover every meta-action a program could take and would therefore
allow for very sophisticated debugging applications. If we had a
__startup__ meta-magic function, we could write a program that would
attach, when the program ran, to a remote debugger. Since each action the
program could take would be represented by a meta-magic function, we could
then remotely step through the program. We could support exactly the level
of debugging we desired and would not be locked into having either too much
or too little information. This would be a miracle for CGI debugging, for
example.
Thoughts and/or suggestions for improvement are welcome!
steve
--
Steven D. Arnold Que quiero sera stevena at permanent.cc
"Fear: The best way out is through." -- Helen Keller
More information about the Python-list
mailing list