From 8ea7c29e554eac7047e253e7442e8dda2c3a69b9 Mon Sep 17 00:00:00 2001 From: Rene Wagner Date: Wed, 27 Nov 2019 13:33:54 +0100 Subject: [PATCH 1/3] (mod) switch to Yajl if available --- lib/gelf/notifier.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/gelf/notifier.rb b/lib/gelf/notifier.rb index fcaf0de..f2a4888 100644 --- a/lib/gelf/notifier.rb +++ b/lib/gelf/notifier.rb @@ -4,8 +4,18 @@ # replace JSON and #to_json with Yajl if available begin - require 'yajl/json_gem' + require 'yajl' + @yailavail = true rescue LoadError + @yailavail = false +end + +def json_dump(obj) + if yailavail + Yajl.dump(obj) + else + JSON.dump(obj) + end end module GELF @@ -163,7 +173,7 @@ def notify_with_level!(message_level, *args) if hash['level'] >= level if default_options['protocol'] == GELF::Protocol::TCP validate_hash(hash) - @sender.send(hash.to_json + "\0") + @sender.send(json_dump(hash) + "\0") else @sender.send_datagrams(datagrams_from_hash(hash)) end @@ -260,7 +270,7 @@ def validate_hash(hash) def serialize_hash(hash) validate_hash(hash) - Zlib::Deflate.deflate(hash.to_json).bytes + Zlib::Deflate.deflate(json_dump(hash)).bytes end def self.stringify_keys(data) From 53142d4ae5874ce1f066d810ee30804492d96bfe Mon Sep 17 00:00:00 2001 From: Rene Wagner Date: Wed, 27 Nov 2019 13:47:44 +0100 Subject: [PATCH 2/3] (mod) fix local variable issue --- lib/gelf/notifier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gelf/notifier.rb b/lib/gelf/notifier.rb index f2a4888..1687ae6 100644 --- a/lib/gelf/notifier.rb +++ b/lib/gelf/notifier.rb @@ -3,11 +3,11 @@ require 'gelf/transport/tcp_tls' # replace JSON and #to_json with Yajl if available +@yailavail = false begin require 'yajl' @yailavail = true rescue LoadError - @yailavail = false end def json_dump(obj) From 13aaee59bb98580d60af8f6d227bdd3fcbf75db7 Mon Sep 17 00:00:00 2001 From: Rene Wagner Date: Wed, 27 Nov 2019 14:08:34 +0100 Subject: [PATCH 3/3] (mod) fix local variable issue #2 --- lib/gelf/notifier.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/gelf/notifier.rb b/lib/gelf/notifier.rb index 1687ae6..7635d4f 100644 --- a/lib/gelf/notifier.rb +++ b/lib/gelf/notifier.rb @@ -3,15 +3,15 @@ require 'gelf/transport/tcp_tls' # replace JSON and #to_json with Yajl if available -@yailavail = false +$yajlavail = false begin require 'yajl' - @yailavail = true + $yajlavail = true rescue LoadError end def json_dump(obj) - if yailavail + if $yajlavail Yajl.dump(obj) else JSON.dump(obj)