mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Allow for exception instances to get serialized in JSON logging
This commit is contained in:
parent
94c8f9913b
commit
23df3d1506
3 changed files with 21 additions and 4 deletions
|
@ -3,3 +3,4 @@ require "logstash/patches/bugfix_jruby_2558"
|
||||||
require "logstash/patches/cabin"
|
require "logstash/patches/cabin"
|
||||||
require "logstash/patches/profile_require_calls"
|
require "logstash/patches/profile_require_calls"
|
||||||
require "logstash/patches/stronger_openssl_defaults"
|
require "logstash/patches/stronger_openssl_defaults"
|
||||||
|
require "logstash/patches/exception_to_json"
|
||||||
|
|
5
logstash-core/lib/logstash/patches/exception_to_json.rb
Normal file
5
logstash-core/lib/logstash/patches/exception_to_json.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class Exception
|
||||||
|
def to_json
|
||||||
|
{"exception_name" => self.class.name, "message" => message}
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,17 +2,18 @@
|
||||||
require "socket"
|
require "socket"
|
||||||
require "logstash/patches"
|
require "logstash/patches"
|
||||||
require "flores/pki"
|
require "flores/pki"
|
||||||
|
require "logstash/json"
|
||||||
|
|
||||||
describe "OpenSSL defaults" do
|
describe "OpenSSL defaults" do
|
||||||
subject { OpenSSL::SSL::SSLContext.new }
|
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 ], [ ... ], ... ]
|
# [ [ ciphername, version, bits, alg_bits ], [ ... ], ... ]
|
||||||
|
|
||||||
# List of cipher names
|
# List of cipher names
|
||||||
let(:ciphers) { subject.ciphers.map(&:first) }
|
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 } }
|
let(:encryption_bits) { subject.ciphers.map { |_, _, _, a| a } }
|
||||||
|
|
||||||
it "should not include any export ciphers" do
|
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
|
# https://github.com/jordansissel/ruby-flores/blob/master/spec/flores/pki_integration_spec.rb
|
||||||
# since these helpers were created to fix this particular issue
|
# since these helpers were created to fix this particular issue
|
||||||
let(:csr) { Flores::PKI::CertificateSigningRequest.new }
|
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.
|
# Please do not use such small keys in production.
|
||||||
let(:key_bits) { 1024 }
|
let(:key_bits) { 1024 }
|
||||||
let(:key) { OpenSSL::PKey::RSA.generate(key_bits, 65537) }
|
let(:key) { OpenSSL::PKey::RSA.generate(key_bits, 65537) }
|
||||||
|
@ -88,3 +89,13 @@ describe "OpenSSL defaults" do
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue