use treq on loggly

This commit is contained in:
Victor Shyba 2018-05-05 02:18:03 -03:00
parent 0bf65836c7
commit 7f88dda0ae

View file

@ -6,8 +6,7 @@ import os
import sys import sys
import traceback import traceback
from txrequests import Session import treq
from requests.exceptions import ConnectionError
from twisted.internet import defer from twisted.internet import defer
import twisted.python.log import twisted.python.log
@ -35,13 +34,13 @@ TRACE = 5
class HTTPSHandler(logging.Handler): class HTTPSHandler(logging.Handler):
def __init__(self, url, fqdn=False, localname=None, facility=None, session=None): def __init__(self, url, fqdn=False, localname=None, facility=None, cookies=None):
logging.Handler.__init__(self) logging.Handler.__init__(self)
self.url = url self.url = url
self.fqdn = fqdn self.fqdn = fqdn
self.localname = localname self.localname = localname
self.facility = facility self.facility = facility
self.session = session if session is not None else Session() self.cookies = cookies or {}
def get_full_message(self, record): def get_full_message(self, record):
if record.exc_info: if record.exc_info:
@ -52,10 +51,8 @@ class HTTPSHandler(logging.Handler):
@defer.inlineCallbacks @defer.inlineCallbacks
def _emit(self, record): def _emit(self, record):
payload = self.format(record) payload = self.format(record)
try: response = yield treq.post(self.url, data=payload, cookies=self.cookies)
yield self.session.post(self.url, data=payload) self.cookies.update(response.cookies())
except ConnectionError:
pass
def emit(self, record): def emit(self, record):
return self._emit(record) return self._emit(record)