def __init__(self, host='localhost', port=24224, tag='', timeout=1, capacity=None): logging.Handler.__init__(self) self.tag = tag self.fluent = FluentSender(host, port, tag, timeout, capacity)
class SafeFluentHandler(logging.Handler): def __init__(self, host='localhost', port=24224, tag='', timeout=1, capacity=None): logging.Handler.__init__(self) self.tag = tag self.fluent = FluentSender(host, port, tag, timeout, capacity) def emit(self, record): try: data = self.format(record) tag = ('%s.%s' % (self.tag, record.levelname.lower())).lstrip('.') self.fluent.send(data, tag, record.created) except (KeyboardInterrupt, SystemExit): raise except: self.handleError(record) def close(self): self.fluent.close() logging.Handler.close(self)