From 57f1197299decdf2fee058681b98cacf18776007 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Mon, 14 Aug 2017 23:21:26 +0200 Subject: [PATCH] Do not alter the message in JSON encoder If required, users can setup filters for that. We shouldnot assume any overly specific use-cases here. --- lib/rackstash/encoders/json.rb | 13 +------------ lib/rackstash/encoders/logstash.rb | 14 ++++++-------- spec/rackstash/encoders/json_spec.rb | 10 ---------- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/lib/rackstash/encoders/json.rb b/lib/rackstash/encoders/json.rb index 01de57f..464a9aa 100644 --- a/lib/rackstash/encoders/json.rb +++ b/lib/rackstash/encoders/json.rb @@ -9,24 +9,13 @@ require 'json' module Rackstash module Encoders # The JSON encoder formats the log event as a single-line JSON string. The - # resulting JSON string contains all data exposed by the buffer. Leading - # and trailing whitespace as well as any ANSI color codes in the `"message"` - # field will be removed. - # - # The resulting string is in the JSON format native to Logstash. You can - # thus ship your logs directly to Logstash without further processing by - # using Logstash's [json codec](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-json.html) - # on the input definition. + # resulting JSON string contains all data exposed by the buffer. # # Most {Adapters} default to use this codec. class JSON # @param event [Hash] a log event as produced by the {Flow} # @return [String] the event as a single-line JSON string def encode(event) - event[FIELD_MESSAGE] = event[FIELD_MESSAGE] - .gsub(/\e\[[0-9;]*m/, EMPTY_STRING) - .strip - ::JSON.dump(event) end end diff --git a/lib/rackstash/encoders/logstash.rb b/lib/rackstash/encoders/logstash.rb index d3e2c4b..fa25dfc 100644 --- a/lib/rackstash/encoders/logstash.rb +++ b/lib/rackstash/encoders/logstash.rb @@ -8,15 +8,13 @@ require 'rackstash/encoders/json' module Rackstash module Encoders - # The JSON encoder formats the log event as a single-line JSON string. The - # resulting JSON string contains all data exposed by the buffer. Leading - # and trailing whitespace as well as any ANSI color codes in the `"message"` - # field will be removed. - # - # The resulting string is in the JSON format native to Logstash. You can - # thus ship your logs directly to Logstash without further processing by - # using Logstash's [json codec](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-json.html) + # The Logstash encoder formats the log event as a single-line JSON string in + # the JSON format native to Logstash. You can thus ship your logs directly + # to Logstash without further processing by using Logstash's + # [json codec](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-json.html) # on the input definition. + # + # The resulting JSON string contains all data exposed by the buffer. class Logstash < JSON # @param event [Hash] a log event as produced by the {Flow} # @return [String] the event as a single-line JSON string diff --git a/spec/rackstash/encoders/json_spec.rb b/spec/rackstash/encoders/json_spec.rb index 5ef2622..b41c642 100644 --- a/spec/rackstash/encoders/json_spec.rb +++ b/spec/rackstash/encoders/json_spec.rb @@ -21,15 +21,5 @@ describe Rackstash::Encoders::JSON do event = { 'message' => "text\nwith\nnewlines" } expect(encoder.encode(event)).to eql '{"message":"text\nwith\nnewlines"}' end - - it 'strips the message from all surrounding whitespace' do - event = { 'message' => "\n\t \nline1\nline2\n \n\t\n" } - expect(encoder.encode(event)).to eql '{"message":"line1\nline2"}' - end - - it 'removes any ANSI color codes from the message' do - event = { 'message' => "Important\n\e[31mRED TEXT\e[0m\nOK" } - expect(encoder.encode(event)).to eql '{"message":"Important\nRED TEXT\nOK"}' - end end end