On Sun, 05 Apr 2009 07:36:45 +0100 "Sam Liddicott" <sam liddicott com> wrote:
I find thay my debug statements are more helpful that my comments; my comments explain what I'm trying to do, by debug statements explain what is being done and why. Debug stataments by definition and out of necessity help one understand the code flow. But why not just write a debug statement instead of a special comment? It's the care in crafting a debug statement that makes it so useful.
I actually use a class for debugging, it's (probably) not fully-featured compared to what some people would like to have, but it works for me. It is somewhat specific to the application I am working on and I haven't had time to generalize it just yet, though that in the plans since I wound up liking the structure of it, but it's a bit of a pain to keep in sync---specifically, lots of things that it uses are currently hard-coded and I'd like it to be more flexible in terms of what it can do. If you're interested, though, it's attached. To use it, first modify it to your needs: * Change the name of the environment variable from ALLTRAY_DEBUG to <YOURAPPNAME>_DEBUG. Do a search/replace, it's in a few different places. * Update the Subsystem enumeration to fit your needs. * Update the switch in emit() to reflect the previous change. * Update subsys_to_string() to fit the changes you made to the Subsystem enumeration. These names are decoration for the debug statements. Then, when you want to use it, make a call to init(), it will read the appropriate environment variable and set things up based on the changes above. It will emit warnings if you place debugging options in the environment variable that the class doesn't handle, and you can combine things: Sunday, 2009-Apr-05 at 03:18:22 - mbt zest - Linux v2.6.29.1 Ubuntu Jaunty:[1-35/2423-0]:src> ALLTRAY_DEBUG=ALL ./alltray -D xterm [2009-04-05 03:18:25 EDT] INFO/MISC: Debugging subsystem setup complete. [2009-04-05 03:18:25 EDT] INFO/CL: Command line options parsed. [2009-04-05 03:18:25 EDT] INFO/PROCESS: Child process 15585 (xterm) now running. [2009-04-05 03:18:27 EDT] INFO/PROCESS: Child process 15585 (xterm) died. [2009-04-05 03:18:27 EDT] INFO/PROCESS: Cleaning up for child... [2009-04-05 03:18:27 EDT] INFO/PROCESS: No more children. Dying. Sunday, 2009-Apr-05 at 03:18:27 - mbt zest - Linux v2.6.29.1 Ubuntu Jaunty:[1-36/2423-0]:src> ALLTRAY_DEBUG=MISC ./alltray -D xterm [2009-04-05 03:18:40 EDT] INFO/MISC: Debugging subsystem setup complete. Sunday, 2009-Apr-05 at 03:18:41 - mbt zest - Linux v2.6.29.1 Ubuntu Jaunty:[1-37/2424-0]:src> ALLTRAY_DEBUG=CL ./alltray -D xterm [2009-04-05 03:18:49 EDT] INFO/CL: Command line options parsed. Sunday, 2009-Apr-05 at 03:18:50 - mbt zest - Linux v2.6.29.1 Ubuntu Jaunty:[1-38/2425-0]:src> ALLTRAY_DEBUG="MISC CL" ./alltray -D xterm [2009-04-05 03:18:59 EDT] INFO/MISC: Debugging subsystem setup complete. [2009-04-05 03:18:59 EDT] INFO/CL: Command line options parsed. Sunday, 2009-Apr-05 at 03:19:00 - mbt zest - Linux v2.6.29.1 Ubuntu Jaunty:[1-39/2426-0]:src> ALLTRAY_DEBUG="MISC PROCESS" ./alltray -D xterm [2009-04-05 03:19:05 EDT] INFO/MISC: Debugging subsystem setup complete. [2009-04-05 03:19:05 EDT] INFO/PROCESS: Child process 15625 (xterm) now running. [2009-04-05 03:19:06 EDT] INFO/PROCESS: Child process 15625 (xterm) died. [2009-04-05 03:19:06 EDT] INFO/PROCESS: Cleaning up for child... [2009-04-05 03:19:06 EDT] INFO/PROCESS: No more children. Dying. Sunday, 2009-Apr-05 at 03:19:06 - mbt zest - Linux v2.6.29.1 Ubuntu Jaunty:[1-40/2427-0]:src> ALLTRAY_DEBUG="MISC PROCESS FUBAR" ./alltray -D xterm ** (alltray:15634): WARNING **: Debug.vala:71: Unrecognized value 'FUBAR' in ALLTRAY_DEBUG [2009-04-05 03:19:51 EDT] INFO/MISC: Debugging subsystem setup complete. [2009-04-05 03:19:51 EDT] INFO/PROCESS: Child process 15635 (xterm) now running. [2009-04-05 03:19:52 EDT] INFO/PROCESS: Child process 15635 (xterm) died. [2009-04-05 03:19:52 EDT] INFO/PROCESS: Cleaning up for child... [2009-04-05 03:19:52 EDT] INFO/PROCESS: No more children. Dying. The Vala source is attached. --- Mike
Attachment:
Debug.vala
Description: Text Data