graylog-labs / gelf-rb

Ruby GELF library (Graylog Extended Log Format)
https://rubygems.org/gems/gelf
MIT License
153 stars 104 forks source link

Opportunistically use Yajl for json encoding #53

Closed emsearcy closed 7 years ago

emsearcy commented 7 years ago

Replace #to_json with a faster Yajl implementation, when Yajl is present.

Also, this fixes the JSON::GeneratorError error: "source sequence is illegal/malformed utf-8", which happens when source hashes do not have correct encoding. In particular, this affects emsearcy/fluent-plugin-gelf, which may have strings coming in with improper encoding, becuase fluentd treats all logs as ASCII-8BIT (see fluent/fluentd#215).

There are other opportunities for performance improvements with Yajl, like using its stream processing to write to the sockets as it syncronously encodes and/or compresses, but I've ignored those for now as they would require architectural changes to gelf-rb.

drAlberT commented 7 years ago

I can confirm that applying this patch and installing Yajl fixes the mismatching Encoding issues

So, please merge this patch and release a new gem version for everyone to easily fix!

Thanks

jh-sz commented 6 years ago

When will this be released? Need it for fluentd

joschi commented 6 years ago

@milgner @tessie ⬆️

peterloron commented 6 years ago

Any update on getting this released now that it is merged? Thanks.