1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-10-17 14:01:01 +00:00

Return the normalized unchanged message from the Message encoder

This commit is contained in:
Holger Just 2017-09-29 23:40:02 +02:00
parent 59c94a8ecc
commit 3584244bc1
2 changed files with 4 additions and 10 deletions

View File

@ -19,12 +19,11 @@ module Rackstash
include Rackstash::Encoders::Helpers::Message include Rackstash::Encoders::Helpers::Message
# @param event [Hash] a log event as produced by the {Flow} # @param event [Hash] a log event as produced by the {Flow}
# @return [String] the `"message"` field of the event. Trailing whitespace # @return [String] the `"message"` field of the event
# will be removed.
def encode(event) def encode(event)
normalize_message(event) normalize_message(event)
event[FIELD_MESSAGE].rstrip event[FIELD_MESSAGE]
end end
end end
end end

View File

@ -14,13 +14,8 @@ describe Rackstash::Encoders::Message do
describe '#encode' do describe '#encode' do
it 'gets the message from the event hash' do it 'gets the message from the event hash' do
event = { 'hello' => 'world', 'message' => ["hello\n", "world"] } event = { 'hello' => 'world', 'message' => ["\n\t \nline1\n", "line2\n \n\t\n"] }
expect(encoder.encode(event)).to eql "hello\nworld" expect(encoder.encode(event)).to eql "\n\t \nline1\nline2\n \n\t\n"
end
it 'rstrips the message' do
event = { 'message' => "\n\t \nline1\nline2\n \n\t\n" }
expect(encoder.encode(event)).to eql "\n\t \nline1\nline2"
end end
end end
end end