diff --git a/lib/rackstash/encoders.rb b/lib/rackstash/encoders.rb index abacfa2..056824b 100644 --- a/lib/rackstash/encoders.rb +++ b/lib/rackstash/encoders.rb @@ -4,3 +4,4 @@ # of the MIT license. See the LICENSE.txt file for details. require 'rackstash/encoders/json' +require 'rackstash/encoders/raw' diff --git a/lib/rackstash/encoders/raw.rb b/lib/rackstash/encoders/raw.rb new file mode 100644 index 0000000..82fd267 --- /dev/null +++ b/lib/rackstash/encoders/raw.rb @@ -0,0 +1,19 @@ +# Copyright 2017 Holger Just +# +# This software may be modified and distributed under the terms +# of the MIT license. See the LICENSE.txt file for details. + +module Rackstash + module Encoders + # The Raw encoder formats the log event as a raw `Hash` containing all data + # exposed by the buffer. This can be used by special log targets which are + # designed to handle hashes as opposed to formatted strings. + class Raw + # @param event [Hash] a log event as produced by the {Flow} + # @return [Hash] the passed `event` + def encode(event) + event + end + end + end +end diff --git a/spec/rackstash/encoders/raw_spec.rb b/spec/rackstash/encoders/raw_spec.rb new file mode 100644 index 0000000..abdb788 --- /dev/null +++ b/spec/rackstash/encoders/raw_spec.rb @@ -0,0 +1,19 @@ +# Copyright 2017 Holger Just +# +# This software may be modified and distributed under the terms +# of the MIT license. See the LICENSE.txt file for details. + +require 'spec_helper' + +require 'rackstash/encoders/raw' + +describe Rackstash::Encoders::Raw do + let(:encoder) { Rackstash::Encoders::Raw.new } + + describe '#encode' do + it 'passes the raw event through' do + event = Object.new + expect(encoder.encode(event)).to equal event + end + end +end