From 021dbc256b83993540f7065831185a78790ef9b7 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Thu, 17 Aug 2017 00:26:43 +0200 Subject: [PATCH] Flush silent Buffers by default With the change to allow ading fields to the Buffer with a Logger interface in the previous commit, we should also flush those Buffers with fields set that way by default. --- lib/rackstash/buffer.rb | 2 +- spec/rackstash/buffer_spec.rb | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/rackstash/buffer.rb b/lib/rackstash/buffer.rb index d22b9a4..caaac86 100644 --- a/lib/rackstash/buffer.rb +++ b/lib/rackstash/buffer.rb @@ -79,7 +79,7 @@ module Rackstash # were just added fields or tags without any logged messages. If this is # `false` and there were no messages logged with {#add_message}, the # buffer will not be flushed to the sink but will be silently dropped. - def initialize(sink, buffering: true, allow_silent: false) + def initialize(sink, buffering: true, allow_silent: true) @sink = sink @buffering = !!buffering @allow_silent = !!allow_silent diff --git a/spec/rackstash/buffer_spec.rb b/spec/rackstash/buffer_spec.rb index c8ffc67..f2089f0 100644 --- a/spec/rackstash/buffer_spec.rb +++ b/spec/rackstash/buffer_spec.rb @@ -14,8 +14,8 @@ describe Rackstash::Buffer do let(:buffer) { described_class.new(sink, **buffer_options) } describe '#allow_silent?' do - it 'defaults to false' do - expect(buffer.allow_silent?).to be false + it 'defaults to true' do + expect(buffer.allow_silent?).to be true end end @@ -101,6 +101,28 @@ describe Rackstash::Buffer do buffer.add_fields(key: 'value') end + context 'when allow_silent?' do + before do + buffer_options[:allow_silent] = true + end + + it 'sets pending? to true' do + buffer.add_fields(key: 'value') + expect(buffer.pending?).to be true + end + end + + context 'when not allow_silent?' do + before do + buffer_options[:allow_silent] = false + end + + it 'does not set pending? to true' do + buffer.add_fields(key: 'value') + expect(buffer.pending?).to be false + end + end + context 'when buffering?' do before do buffer_options[:buffering] = true