Esempio n. 1
0
 def __init__(self,
              host,
              port,
              url,
              secure=False,
              credentials=None,
              context=None,
              tags=None,
              message_type='logstash',
              fqdn=False,
              version=0,
              level='NOTSET'):
     super(HTTPLogstashHandler, self).__init__(level)
     if not secure and context is not None:
         raise ValueError(
             "context parameter only makes sense with secure=True")
     if version == 1:
         self.formatter = formatter.LogstashFormatterVersion1(
             message_type, tags, fqdn)
     else:
         self.formatter = formatter.LogstashFormatterVersion0(
             message_type, tags, fqdn)
     self.tags = tags
     self.port = port
     self.host = host
     self.url = url
     self.method = 'POST'
     self.secure = secure
     self.credentials = credentials
     self.context = context
Esempio n. 2
0
    def __init__(self,
                 host,
                 port=5959,
                 message_type='logstash',
                 tags=None,
                 fqdn=False,
                 version=0,
                 ssl=True,
                 ssl_verify=True,
                 keyfile=None,
                 certfile=None,
                 ca_certs=None,
                 log_attrs=None,
                 extra_fields=None):
        super(TCPLogstashHandler, self).__init__(host, port)

        self.ssl = ssl
        self.ssl_verify = ssl_verify
        self.keyfile = keyfile
        self.certfile = certfile
        self.ca_certs = ca_certs

        if version == 1:
            self.formatter = formatter.LogstashFormatterVersion1(
                message_type, tags, fqdn, log_attrs, extra_fields)
        else:
            self.formatter = formatter.LogstashFormatterVersion0(
                message_type, tags, fqdn, log_attrs, extra_fields)
Esempio n. 3
0
    def __init__(self, host, port=5959, message_type='logstash', tags=None,
                 fqdn=False, version=0, *args, **kwargs):
        super(TCPLogstashHandler, self).__init__(host, port, *args, **kwargs)

        if version == 1:
            self.formatter = formatter.LogstashFormatterVersion1(
                message_type, tags, fqdn)
        else:
            self.formatter = formatter.LogstashFormatterVersion0(
                message_type, tags, fqdn)
Esempio n. 4
0
 def __init__(self,
              host,
              port=5959,
              message_type='logstash',
              fqdn=False,
              version=0):
     super(TCPLogstashHandler, self).__init__(host, port)
     if version == 1:
         self.formatter = formatter.LogstashFormatterVersion1(
             message_type, [], fqdn)
     else:
         self.formatter = formatter.LogstashFormatterVersion0(
             message_type, [], fqdn)
    def emit(self, record):
        record.msg = self.format(record) + '\n'
        logstash_formatter = formatter.LogstashFormatterVersion1(
            'logstash', getattr(self, 'tags', []),
            getattr(self, 'fqdn', False))

        message = logstash_formatter.format(record)
        message_string = message.decode()
        message_dict = json.loads(message_string)
        message_dict['type'] = 'django_log'
        message = json.dumps(message_dict) + '\n'
        try:
            self.sock.send(message.encode())
        except Exception as e:
            print(e)
Esempio n. 6
0
    def __init__(self,
                 redis_url,
                 queue_name='',
                 message_type='logstash',
                 tags=None):
        """
        初始化,延迟时间默认1秒钟
        """
        logging.Handler.__init__(self)
        self.queue_name = queue_name
        pool = redis.BlockingConnectionPool.from_url(redis_url,
                                                     max_connections=600,
                                                     timeout=1)
        self.client = redis.Redis(connection_pool=pool)

        self.formatter = formatter.LogstashFormatterVersion1(message_type,
                                                             tags,
                                                             fqdn=False)