Пример #1
0
        if os.getpid() != self.pid:
            self.connect()

        msg = self.format(record).rstrip('\n')
        # print("SEND".format(repr(msg)))
        try:
            s = chr(record.levelno) + msg
            self.sock.send(s.encode('utf8'), zmq.NOBLOCK)
        except zmq.error.Again:
            # drop :/
            pass


def add_file_handler(log):
    """
  Function to add the file log handler to swaglog.
  This can be used to store logs when logmessaged is not running.
  """
    handler = get_file_handler()
    handler.setFormatter(SwagLogFileFormatter(log))
    log.addHandler(handler)


cloudlog = log = SwagLogger()
log.setLevel(logging.DEBUG)

outhandler = logging.StreamHandler()
log.addHandler(outhandler)
# logs are sent through IPC before writing to disk to prevent disk I/O blocking
log.addHandler(UnixDomainSocketHandler(SwagFormatter(log)))
Пример #2
0
        super(SwagLogstashHandler, self).__init__(host,
                                                  port,
                                                  database_path=None,
                                                  transport=UdpTransport)
        self.name = name
        if not isinstance(formatter, SwagLogstashFormatter):
            raise ValueError("formatter must be swag")
        self.setFormatter(formatter)

    def emit(self, record):
        record.name = self.name
        super(SwagLogstashHandler, self).emit(record)


if __name__ == "__main__":
    from common.logging_extra import SwagLogger
    log = SwagLogger()
    ls_formatter = SwagLogstashFormatter(log)
    ls_handler = SwagLogstashHandler("logstash.comma.life", 5040, "pipeline",
                                     ls_formatter)
    log.addHandler(ls_handler)
    s_handler = logging.StreamHandler()
    log.addHandler(s_handler)

    log.info("asynclogtest %s", "1")
    log.info({'asynclogtest': 2})
    log.warning("asynclogtest warning")
    log.error("asynclogtest error")
    log.critical("asynclogtest critical")
    log.event("asynclogtest", a="b")