diff --git a/logstash-core/lib/logstash/patches.rb b/logstash-core/lib/logstash/patches.rb index 8a3b3aa85..283d74aa3 100644 --- a/logstash-core/lib/logstash/patches.rb +++ b/logstash-core/lib/logstash/patches.rb @@ -3,3 +3,4 @@ require "logstash/patches/bugfix_jruby_2558" require "logstash/patches/cabin" require "logstash/patches/profile_require_calls" require "logstash/patches/stronger_openssl_defaults" +require "logstash/patches/exception_to_json" diff --git a/logstash-core/lib/logstash/patches/exception_to_json.rb b/logstash-core/lib/logstash/patches/exception_to_json.rb new file mode 100644 index 000000000..00de79f25 --- /dev/null +++ b/logstash-core/lib/logstash/patches/exception_to_json.rb @@ -0,0 +1,5 @@ +class Exception + def to_json + {"exception_name" => self.class.name, "message" => message} + end +end diff --git a/logstash-core/spec/logstash/patches_spec.rb b/logstash-core/spec/logstash/patches_spec.rb index f22db6d07..f97d4ea20 100644 --- a/logstash-core/spec/logstash/patches_spec.rb +++ b/logstash-core/spec/logstash/patches_spec.rb @@ -2,17 +2,18 @@ require "socket" require "logstash/patches" require "flores/pki" +require "logstash/json" describe "OpenSSL defaults" do subject { OpenSSL::SSL::SSLContext.new } - # OpenSSL::SSL::SSLContext#ciphers returns an array of + # OpenSSL::SSL::SSLContext#ciphers returns an array of # [ [ ciphername, version, bits, alg_bits ], [ ... ], ... ] - + # List of cipher names let(:ciphers) { subject.ciphers.map(&:first) } - # List of cipher encryption bit strength. + # List of cipher encryption bit strength. let(:encryption_bits) { subject.ciphers.map { |_, _, _, a| a } } it "should not include any export ciphers" do @@ -35,7 +36,7 @@ describe "OpenSSL defaults" do # https://github.com/jordansissel/ruby-flores/blob/master/spec/flores/pki_integration_spec.rb # since these helpers were created to fix this particular issue let(:csr) { Flores::PKI::CertificateSigningRequest.new } - # Here, I use a 1024-bit key for faster tests. + # Here, I use a 1024-bit key for faster tests. # Please do not use such small keys in production. let(:key_bits) { 1024 } let(:key) { OpenSSL::PKey::RSA.generate(key_bits, 65537) } @@ -88,3 +89,13 @@ describe "OpenSSL defaults" do end end end + +describe "exceptions used json logging hashes" do + let(:exception) { ArgumentError.new("so you want an argument, huh?") } + let(:result) { [] } + + it "should not raise errors" do + expect { result << LogStash::Json.dump({"error" => exception}) }.not_to raise_error + expect(result[0]).to match(/ArgumentError.*so you want an argument/) + end +end