Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions graypy/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -750,6 +750,7 @@ def __init__(
self.host = host
self.port = port
self.path = path
self.useSSL = useSSL
self.timeout = timeout
self.headers = {}

Expand All @@ -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)