Python logging module: a good reference is http://www.red-dove.com/python_logging.html.
It looks to me to be horribly over engineered.
It is kinda cool:
#
import logging
import logging.handlers
#
# Set up basic handling.
#
logging.basicConfig()
log = logging.getLogger( "Test")
#
# Log info messages and higher.
#
log.setLevel( logging.INFO)
#
# An info message
#
log.info( "Blah")
#
# Add a handler that will send email
#
log.addHandler( logging.handlers.SMTPHandler( <server>, <from>, <to>, <subject>))
try:
h = wang
except:
log.exception( "oopsy daisy")
The output looks like this:
INFO:Test:Blah
ERROR:Test:oopsy daisy
Traceback (most recent call last):
File "\Tmp\try.py", line 13, in ?
h = wang
NameError: name 'wang' is not defined
I like putting prints in my scripts and I never get round to tidying them up. Maybe I could get into the habit of using this.
|