To register standard output, you can use a stdout wrapper like this one:
from __future__ import with_statement class OutWrapper(object): def __init__(self, realOutput, logFileName): self._realOutput = realOutput self._logFileName = logFileName def _log(self, text): with open(self._logFileName, 'a') as logFile: logFile.write(text) def write(self, text): self._log(text) self._realOutput.write(text)
Then you should initialize it in your main Python file (the one that runs everything):
import sys sys.stdout = OutWrapper(sys.stdout, r'c:\temp\log.txt')
As for exception logging, the easiest way is to wrap MainLoop wx.App method in try..except, and then extract the exception information, save it somehow, and then re-create the exception via raise , for example:
try: app.MainLoop() except: exc_info = sys.exc_info() saveExcInfo(exc_info)
Jinx
source share