lib/logjam_agent/request.rb in logjam_agent-0.5.7 vs lib/logjam_agent/request.rb in logjam_agent-0.5.8
- old
+ new
@@ -1,6 +1,10 @@
-require "json"
+begin
+ require "oj"
+rescue LoadError
+ require "json"
+end
module LogjamAgent
class Request
attr_reader :caller_id, :fields
@@ -35,15 +39,27 @@
end
end
def forward
engine = @fields.delete(:engine)
- @forwarder.forward(@fields.to_json, engine)
+ @forwarder.forward(encode_payload, engine)
rescue Exception => e
handle_forwarding_error(e)
end
private
+
+ if defined?(Oj)
+ def encode_payload
+ Oj.dump(@fields, :mode => :compat)
+ rescue
+ @fields.to_son
+ end
+ else
+ def encode_payload
+ @fields.to_json
+ end
+ end
def format_time(t)
# iso time with microseconds
t.strftime("%Y-%m-%dT%H:%M:%S.#{"%06d" % t.usec}")
end