Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace explicit Yajl support with MultiJson #73

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions gelf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<mocha>, ["~> 1.1.0"])
s.add_development_dependency(%q<test-unit>, ["~> 3.2.0"])
s.add_runtime_dependency(%q<json>, [">= 0"])
s.add_runtime_dependency(%q<multi_json>, ["~> 1.0"])
else
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
s.add_dependency(%q<jeweler>, ["~> 2.1.1"])
s.add_dependency(%q<rack>, ["< 2.0"])
s.add_dependency(%q<mocha>, ["~> 1.1.0"])
s.add_dependency(%q<test-unit>, ["~> 3.2.0"])
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<multi_json>, ["~> 1.0"])
end
else
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
Expand All @@ -74,6 +76,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<mocha>, ["~> 1.1.0"])
s.add_dependency(%q<test-unit>, ["~> 3.2.0"])
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<multi_json>, ["~> 1.0"])
end
end

10 changes: 3 additions & 7 deletions lib/gelf/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
require 'gelf/transport/tcp'
require 'gelf/transport/tcp_tls'

# replace JSON and #to_json with Yajl if available
begin
require 'yajl/json_gem'
rescue LoadError
end
require 'multi_json'

module GELF
# Graylog2 notifier.
Expand Down Expand Up @@ -163,7 +159,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(MultiJson.dump(hash) + "\0")
else
@sender.send_datagrams(datagrams_from_hash(hash))
end
Expand Down Expand Up @@ -260,7 +256,7 @@ def validate_hash(hash)
def serialize_hash(hash)
validate_hash(hash)

Zlib::Deflate.deflate(hash.to_json).bytes
Zlib::Deflate.deflate(MultiJson.dump(hash)).bytes
end

def self.stringify_keys(data)
Expand Down