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/profile_require_calls"
|
||||
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,6 +2,7 @@
|
|||
require "socket"
|
||||
require "logstash/patches"
|
||||
require "flores/pki"
|
||||
require "logstash/json"
|
||||
|
||||
describe "OpenSSL defaults" do
|
||||
subject { OpenSSL::SSL::SSLContext.new }
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue