mirror of
https://github.com/meineerde/rackstash.git
synced 2026-02-01 01:37:12 +00:00
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.
This commit is contained in:
parent
cc8e5db6b4
commit
57f1197299
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user