import logging import logstash_formatter import gunicorn.glogging from gunicorn import util class LogstashLogger(gunicorn.glogging.Logger): def _set_handler(self, log, output, fmt): # remove previous gunicorn log handler h = self._get_gunicorn_handler(log) if h: log.handlers.remove(h) if output is not None: if output == "-": h = logging.StreamHandler() else: util.check_is_writeable(output) h = logging.FileHandler(output) h.setFormatter(logstash_formatter.LogstashFormatter()) h._gunicorn = True log.addHandler(h)