1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-12-19 15:01:12 +00:00

Allow to define a suitable default encoder per adapter

The global default (unless overwritten by an adapter class) is to use
the JSON encoder since it's the most versatile and flexible option for a
logger today.
This commit is contained in:
Holger Just 2017-06-06 20:59:23 +02:00
parent bf178ef36d
commit b3f9a63253
2 changed files with 15 additions and 0 deletions

View File

@ -41,6 +41,15 @@ module Rackstash
def initialize(*) def initialize(*)
end end
# Return a new Encoder instance which can be used with the concrete adapter
# If no explicit encoder is defined in a {Flow}, this encoder will be used
# there
#
# @return [#call] an encoder
def default_encoder
Rackstash::Encoders::JSON.new
end
# Close the underlying log device if supported by it. # Close the underlying log device if supported by it.
# #
# This method needs to be overwritten in child classes. By default, this # This method needs to be overwritten in child classes. By default, this

View File

@ -18,6 +18,12 @@ describe Rackstash::Adapters::Adapter do
end end
end end
describe '.default_encoder' do
it 'returns an encoder' do
expect(adapter.default_encoder).to respond_to(:encode)
end
end
describe '#close' do describe '#close' do
it 'does nothing' do it 'does nothing' do
expect(adapter.close).to be nil expect(adapter.close).to be nil