-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You may also want to try a error handling like this.

It is platform clean and uses the system standard logging routines.


import os, logging, logging.handlers


def eventlogger(level,message):
        """
        Sent trapped events to NT application event logger
        """

        if os.name == "nt":
                
                logger = logging.getLogger("")
                logger.setLevel(logging.DEBUG)
                ntl = logging.handlers.NTEventLogHandler("Program Event Logger 
Message")
                logger.addHandler(ntl)
                
                try:
                        method = getattr(logger,level)
                        message = "%s message: %s" % 
(level.capitalize(),message)
                        method(message)
                        sys.exit(0)
                except AttributeError:
                        method = logger.critical
                        message = "Uncoded event level"
                        method(message)
                        sys.exit(1)
                
        else :
                import syslog, time
                timestamp = time.asctime(time.localtime(time.time()))
                logmsg = "Event Logger -   %s  - %s :: $s " % (timestamp,
level.capitalize(),message)
                syslogg.syslog(logmsg)
                



You then call it as a function from wherever an error gets raised.

       msg="OH NO - blue screen of death"
       eventlogger("error",msg)

       msg="OH NO - system slow - scary but you will live"
       eventlogger("warning",msg)

       msg="Shh - don't tell anyone but it worked"
       eventlogger("info",msg)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)
Comment: GnuPT 2.7.2

iD8DBQFEmEB2Dvn/4H0LjDwRAhlmAKCzch2JVynMsNcCY9Cnu8crMqN5fQCfQJWu
ZT8frQiRZXKJZMLeGnyeFbM=
=zCBc
-----END PGP SIGNATURE-----
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to