[Tutor] Logging module

Dick Moores rdm at rcblue.com
Sat May 10 15:36:53 CEST 2008


I don't understand how to use this. I've read 
<http://docs.python.org/lib/module-logging.html> and 
<http://blog.doughellmann.com/2007/05/pymotw-logging.html>.

I thought I'd try with a script that screws up:

a = "qwerty"
b = a*b

But how to use the logging module to log the report of the screw up? 
Right now I don't care about the various levels. I just want to get 
something into a log file.

Hellmann suggest this:

import logging
LOG_FILENAME = '/tmp/logging_example.out'
logging.basicConfig(filename=LOG_FILENAME,     level=logging.DEBUG,)
logging.debug('This message should go to the log file')

But where to put it? In my above script?

Thanks,

Dick Moores




More information about the Tutor mailing list