Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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