Peter's Blog 10.3.2004

2004-03-10

Written KLog module.

Written KLog module. This allows me to go:

#
import KLog

KLog.HookError()
KLog.SendEmail()

print "Wifffle"

wang()
HookError

hooks the global exception handler so errors are written to log output.

SendEmail

cause it to email me error logs

There is also:

KLog.SetLogFile( "c:\\tmp\\log.txt")

which writes log output to a log file.

posted at 16:04:16    #    comment []    trackback []
 

Python logging module:

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.

posted at 13:54:08    #    comment []    trackback []
 

ISilo'd the blog and it looks good to me.

ISilo'd the blog and it looks good to me. My biggest dislike is the way long lines of preformatted text overflow the boxes. I think there are two solutions:

  1. Wrap the long lines in python

  2. Remove the boxes, go for horizontal bars instead.

0ption 1 is a bodge, 2 is the way to go but it's a shame as I like the boxes.

posted at 09:38:08    #    comment []    trackback []
March 2004
MoTuWeThFrSaSu
1 2 3 4 5 6 7
8 91011121314
15161718192021
22232425262728
293031    
Feb
2004
 Apr
2004

A blog documenting Peter's dabblings with Python, Gentoo Linux and any other cool toys he comes across.

XML-Image Letterimage

© 2004, Peter Wilkinson

Bisi and me