in reply to Re^4: I usually debug via...
in thread I usually debug via...

You might like to check out http://log4perl.sourceforge.net/ which is a library for doing exactly this kind of thing.