[Tutor] Conventions for code snippets for debugging and testing?
ricaraoz at gmail.com
Fri Apr 11 16:22:39 CEST 2008
Robert Kirkpatrick wrote:
> Hi All,
> Just wondering if there are any basic conventions for including code
> snippets that are for testing / debugging only?
> For example, you could set a boolean variable called DEBUG, then have
> snippets of code like:
> if DEBUG:
> do stuff
> do otherstuff
> The use case I'm dealing with right now is to query the SVN commits for a
> weekly period and report on each user for that time period. If I'm testing
> though, I only want to cycle through a few users, not all of them.
> I'm thinking there has to be something slicker than that but maybe not...
Check the logging standard module. I use it this way (from the manual) :
format='%(asctime)s %(levelname)s %(message)s',
logging.debug('A debug message')
logging.warning('A shot across the bows')
I put the logging.debug('dbg messg') at the appropriate places. When I'm
done then I replaces the logging.basicConfig(level=logging.CRITICAL or
just 100 so as not to log anything and that's it.
You have 6 preset levels, but you can define as many levels you want.
Level Numeric value
Once you have your logging set you use a tail program to watch your log
and see what's going on.
More information about the Tutor