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

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.
This commit is contained in:
Holger Just 2017-08-17 00:26:43 +02:00
parent 013d0f7d92
commit 021dbc256b
2 changed files with 25 additions and 3 deletions

View File

@ -79,7 +79,7 @@ module Rackstash
# were just added fields or tags without any logged messages. If this is # were just added fields or tags without any logged messages. If this is
# `false` and there were no messages logged with {#add_message}, the # `false` and there were no messages logged with {#add_message}, the
# buffer will not be flushed to the sink but will be silently dropped. # 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 @sink = sink
@buffering = !!buffering @buffering = !!buffering
@allow_silent = !!allow_silent @allow_silent = !!allow_silent

View File

@ -14,8 +14,8 @@ describe Rackstash::Buffer do
let(:buffer) { described_class.new(sink, **buffer_options) } let(:buffer) { described_class.new(sink, **buffer_options) }
describe '#allow_silent?' do describe '#allow_silent?' do
it 'defaults to false' do it 'defaults to true' do
expect(buffer.allow_silent?).to be false expect(buffer.allow_silent?).to be true
end end
end end
@ -101,6 +101,28 @@ describe Rackstash::Buffer do
buffer.add_fields(key: 'value') buffer.add_fields(key: 'value')
end 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 context 'when buffering?' do
before do before do
buffer_options[:buffering] = true buffer_options[:buffering] = true