diff --git a/graypy/handler.py b/graypy/handler.py index 48e77e90e..2467f3ecc 100644 --- a/graypy/handler.py +++ b/graypy/handler.py @@ -723,7 +723,7 @@ class GELFHTTPHandler(BaseGELFHandler): """GELF HTTP handler""" def __init__( - self, host, port=12203, compress=True, path="/gelf", timeout=5, **kwargs + self, host, port=12203, compress=True, path="/gelf", useSSL=False, timeout=5, **kwargs ): """Initialize the GELFHTTPHandler @@ -750,6 +750,7 @@ def __init__( self.host = host self.port = port self.path = path + self.useSSL = useSSL self.timeout = timeout self.headers = {} @@ -764,8 +765,13 @@ def emit(self, record): and emit to Graylog via a HTTP POST request. :type record: logging.LogRecord """ - pickle = self.makePickle(record) - connection = httplib.HTTPConnection( - host=self.host, port=self.port, timeout=self.timeout - ) - connection.request("POST", self.path, pickle, self.headers) + try: + pickle = self.makePickle(record) + + connectionClass = httplib.HTTPSConnection if self.useSSL else httplib.HTTPConnection + connection = connectionClass( + host=self.host, port=self.port, timeout=self.timeout + ) + connection.request("POST", self.path, pickle, self.headers) + except Exception as e: + print("Failed to send GELF via HTTP: ", e)