From: Andy T. <an...@cr...> - 2001-08-24 09:52:26
|
Evening all, I was idly perusing the sample code (I do that on Friday nights, you know) and I discovered that none of the samples uses the logging module that is included in the prototype. Determined to remedy this oversight I set about changing one of the samples and ten minutes later (beat that Kevin!), worldclock has been changed. The code in CVS has been updated and should be included in the next release. If you are running it without a console window you will not notice any difference. If you have a console window the regular messages that used to be output are no longer. To get output you need to enable logging with the -l switch on the command line. Switch it on and all of the messages will be written to a file called pythoncard.log in the same directory as worlclock.py. Note that this file is overwritten each time you run the application, you have been warned! Luckily the changes to the code were quite simple, just import the log class; """ from PythonCardPrototype.log import Log """ Then add a couple of lines to the __init__ method of your application class; """ self.log = Log.getInstance() self.log.enableLevels( [ Log.ERROR, Log.WARNING, Log.DEBUG, Log.INFO ] ) """ Then, when you want to output a message just use; self.log.info( < whatever you need to output > ) or self.log.debug( ... ) self.log.error( ... ) self.log.warning( ... ) When calling any of these methods you can (I'm told) include any number and combination of items (well, OK - objects), their 'repr' methods will be called to render them into a format suitable for writing to a file. Note that I've enabled all of the log levels in the code, so running the sample application with -l you will see all of the messages that are output. As a general rule of thumb it is better to only enable ERROR and WARNING and to disable DEBUG and INFO. When you are actively changing or developing a module turn these on but don't forget to turn them back off when you ship. Regards, Andy -- ----------------------------------------------------------------------- From the desk of Andrew J Todd esq. "Shave my poodle!" |