import sysfsock = open('error.log', 'w')sys.stderr = fsockraise Exception, 'this error will be logged'