Skip to content

Commit

Permalink
Parse using Yajl.dump when available
Browse files Browse the repository at this point in the history
  • Loading branch information
griff committed Oct 9, 2017
1 parent aaeefc3 commit 9a4390a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/gelf/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
require 'gelf/transport/tcp'
require 'gelf/transport/tcp_tls'

# replace JSON and #to_json with Yajl if available
begin
require 'yajl/json_gem'
require 'yajl'
def json_dump(obj)
Yajl.dump(obj)
end
rescue LoadError
def json_dump(obj)
JSON.dump(obj)
end
end

module GELF
Expand Down Expand Up @@ -163,7 +168,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
Expand Down Expand Up @@ -260,7 +265,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(hash)
Expand Down

0 comments on commit 9a4390a

Please sign in to comment.