Add to system log
|
import syslog, sys, StringIO, traceback, os
def logexception(includetraceback = 0): exctype, exception, exctraceback = sys.exc_info() excclass = str(exception.__class__) message = str(exception)
if not includetraceback: syslog.syslog(syslog.LOG_ERR, "%s: %s" % (excclass, message)) else: excfd = StringIO.StringIO() traceback.print_exception(exctype, exception, exctraceback, None, excfd) for line in excfd.getvalue().split("n"): syslog.syslog(syslog.LOG_ERR, line)
def initsyslog(): syslog.openlog("%s[%d]" % (os.path.basename(sys.argv[0]), os.getpid()),0, syslog.LOG_DAEMON) syslog.syslog("Started.")
initsyslog() logexception(0) logexception(1) syslog.syslog("done")
|
|
|
|
|