Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency in LogstashFormatterBase.serialize method for python 3 #30

Open
magrynow opened this issue Apr 20, 2015 · 1 comment
Open

Comments

@magrynow
Copy link

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.

@chekunkov
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants