Skip to content

Conversation

@matt-snider
Copy link
Contributor

Hi @vklochan

I ran into a logging error today involving a non-json serializable value in a situation similar to the following:

test_logger.info('testing', extra={'test_dict': {'foo': object()}})

Which would result in:

TypeError: <object object at 0x7f768bcef130> is not JSON serializable

Some of this is prevented in formatter.py#L45 where repr() is called on any non "easy" types. This is essentially what adding the default argument to json.dumps() would do, with the addition that it would also take care of nested structures. I can of course update my PR to use repr() instead of str().

@mozz100
Copy link

mozz100 commented May 26, 2017

I hit this too. In my case the call to logging is from inside django. The code there is outside my control, so I can't work around this easily.

@vklochan could you consider merging this and publishing a new version on pypi?

@matt-snider thanks for sharing the fix with the world - I only found it after writing my own, inferior solution to the same problem

@matt-snider
Copy link
Contributor Author

@mozz100 Glad it could be of some use to someone else 😃.Hoping this can be merged at some point soon as well but it's been quite awhile

@mozz100
Copy link

mozz100 commented Apr 30, 2019

To me it feels like this project isn't being maintained any more (see https://github.com/vklochan/python-logstash/graphs/code-frequency)

Recommend others might be interested in developments at https://github.com/eht16/python-logstash-async

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

Successfully merging this pull request may close these issues.

2 participants