vklochan/python-logstash

Inconsistency in LogstashFormatterBase.serialize method for python 3

magrynow opened this issue · 1 comments

For python 3 LogstashFormatterBase.serialize method returns bytes instead of string. This incosistency results in no possibility in reusing this formatter with buildin handlers like pythons StreamHandlers (e.g. FileHandler), because it expects string object returned from formatter.

For python 2.X LogstashFormatterBase.serialize method behaves correct returning string.

Same issue here. Python 3.5, when I use LogstashFormatter with FileHandler I get:

--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/logging/__init__.py", line 982, in emit
    stream.write(msg)
TypeError: write() argument must be str, not bytes

The issue is fixed once I override serialize to return json.dumps(message). What maintainers think about removing version check here and using json.dumps for all the versions? It makes sense to convert formatted messages to bytes in handlers before sending to a socket.