def _handleFailedExecutor(self, agentID, executorID=None):
        """
        Should be called when we find out an executor has failed.
        
        Gets the log from some container (since we are never handed a container
        ID) that ran on the given executor on the given agent, if the agent is
        still up, and dumps it to our log. All IDs are strings.
        
        If executorID is None, dumps all executors from the agent.
        
        Useful for debugging failing executor code.
        """
        
        log.warning("Handling failure of executor '%s' on agent '%s'.",
                    executorID, agentID)
        
        try:
            # Look up the IP. We should always know it unless we get answers
            # back without having accepted offers.
            agentAddress = self.agentsByID[agentID]
            
            # For now we assume the agent is always on the same port. We could
            # maybe sniff this from the URL that comes in the offer but it's
            # not guaranteed to be there.
            agentPort = 5051
            
            # We need the container ID to read the log, but we are never given
            # it, and I can't find a good way to list it, because the API only
            # seems to report running containers. So we dump all the avaiilable
            # files with /files/debug and look for one that looks right.
            filesQueryURL = errorLogURL = "http://%s:%d/files/debug" % \
                (agentAddress, agentPort)
                
            # Download all the root mount points, which are in an object from
            # mounted name to real name
            filesDict = json.loads(urlopen(filesQueryURL).read())
            
            log.debug('Available files: %s', repr(filesDict.keys()))
            
            # Generate filenames for each container pointing to where stderr should be
            stderrFilenames = []
            # And look for the actual agent logs.
            agentLogFilenames = []
            for filename in filesDict.iterkeys():
                if (self.frameworkId in filename and agentID in filename and
                    (executorID is None or executorID in filename)):
                    
                    stderrFilenames.append("%s/stderr" % filename)
                elif filename.endswith("log"):
                    agentLogFilenames.append(filename)
                    
            if '/slave/log' not in agentLogFilenames:
                # Look here even if not reported.
                agentLogFilenames.append('/slave/log')
                    
            if len(stderrFilenames) == 0:
                log.warning("Could not find any containers in '%s'." % filesDict)
            
            for stderrFilename in stderrFilenames:
                try:
            
                    # According to
                    # http://mesos.apache.org/documentation/latest/sandbox/ we can use
                    # the web API to fetch the error log.
                    errorLogURL = "http://%s:%d/files/download?path=%s" % \
                        (agentAddress, agentPort, quote_plus(stderrFilename))
                        
                    log.warning("Attempting to retrieve executor error log: %s", errorLogURL)
                        
                    for line in urlopen(errorLogURL):
                        # Warn all the lines of the executor's error log
                        log.warning("Executor: %s", line.rstrip())
                        
                except Exception as e:
                    log.warning("Could not retrieve exceutor log due to: '%s'.", e)
                    log.warning(traceback.format_exc())
                    
            for agentLogFilename in agentLogFilenames:
                try:
                    agentLogURL = "http://%s:%d/files/download?path=%s" % \
                        (agentAddress, agentPort, quote_plus(agentLogFilename))
                        
                    log.warning("Attempting to retrieve agent log: %s", agentLogURL)
                    
                    for line in urlopen(agentLogURL):
                        # Warn all the lines of the agent's log
                        log.warning("Agent: %s", line.rstrip())
                except Exception as e:
                    log.warning("Could not retrieve agent log due to: '%s'.", e)
                    log.warning(traceback.format_exc())
                
        except Exception as e:
            log.warning("Could not retrieve logs due to: '%s'.", e)
            log.warning(traceback.format_exc())