From 0aa39483dd32b1a178d450153697292bf6ba2eb5 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Wed, 7 Jun 2017 13:00:24 +0200 Subject: [PATCH] Add Raw encoder which just passes the log event --- lib/rackstash/encoders.rb | 1 + lib/rackstash/encoders/raw.rb | 19 +++++++++++++++++++ spec/rackstash/encoders/raw_spec.rb | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 lib/rackstash/encoders/raw.rb create mode 100644 spec/rackstash/encoders/raw_spec.rb 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