diff --git a/lib/rackstash/buffer.rb b/lib/rackstash/buffer.rb index 888a1f0..f983639 100644 --- a/lib/rackstash/buffer.rb +++ b/lib/rackstash/buffer.rb @@ -74,16 +74,15 @@ module Rackstash # @param buffering [Boolean] When set to `true`, this buffer is considered # to be buffering data. When buffering, logged messages will not be # flushed immediately but only with an explicit call to {#flush}. - # @param allow_empty [Boolean] When set to `true` the data in this buffer - # will be flushed to the sink, even if no messages were logged but there - # were just added fields or tags. If this is `false` and there were no - # explicit changes to the buffer (e.g. a logged message, added tags or - # fields), the buffer will not be flushed to the sink but will be silently - # dropped. - def initialize(sink, buffering: true, allow_empty: false) + # @param allow_silent [Boolean] When set to `true` the data in this buffer + # will be flushed to the sink, even if there + # 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) @sink = sink @buffering = !!buffering - @allow_empty = !!allow_empty + @allow_silent = !!allow_silent # initialize the internal data structures for fields, tags, ... clear @@ -145,14 +144,15 @@ module Rackstash end # When set to `true` in {#initialize}, the data in this buffer will be - # flushed to the sink, even if no messages were logged but there were just - # added fields or tags. If this is `false` and there were no explicit - # changes to the buffer (e.g. a logged message, added tags or fields), the - # buffer will not be flushed to the sink but will be silently dropped. + # flushed to the sink, even if there were just added fields or tags but no + # 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. # # @return [Boolean] - def allow_empty? - @allow_empty + def allow_silent? + @allow_silent end # When set to `true` in {#initialize}, this buffer is considered to be @@ -207,13 +207,13 @@ module Rackstash # default, a new buffer is not pending and will not be flushed to the sink. # Each time there is a new message logged, this is set to `true` for the # buffer. For changes of tags or fields, the `pending?` flag is only - # flipped to `true` if {#allow_empty?} is set to `true`. + # flipped to `true` if {#allow_silent?} is set to `true`. # # @return [Boolean] `true` if the buffer has stored data which should be # flushed. def pending? return true if @messages.any? - if allow_empty? + if allow_silent? return true unless @fields.nil? || @fields.empty? return true unless @tags.nil? || @tags.empty? end diff --git a/spec/rackstash/buffer_spec.rb b/spec/rackstash/buffer_spec.rb index 3994c0a..5f10d43 100644 --- a/spec/rackstash/buffer_spec.rb +++ b/spec/rackstash/buffer_spec.rb @@ -13,9 +13,9 @@ describe Rackstash::Buffer do let(:sink) { instance_double(Rackstash::Sink) } let(:buffer) { described_class.new(sink, **buffer_options) } - describe '#allow_empty?' do + describe '#allow_silent?' do it 'defaults to false' do - expect(buffer.allow_empty?).to be false + expect(buffer.allow_silent?).to be false end end @@ -264,10 +264,10 @@ describe Rackstash::Buffer do expect(buffer.pending?).to be true end - context 'with allow_empty: true' do + context 'with allow_silent: true' do before do - buffer_options[:allow_empty] = true - expect(buffer.allow_empty?).to be true + buffer_options[:allow_silent] = true + expect(buffer.allow_silent?).to be true end it 'defaults to false' do @@ -285,10 +285,10 @@ describe Rackstash::Buffer do end end - context 'with allow_empty: false' do + context 'with allow_silent: false' do before do - buffer_options[:allow_empty] = false - expect(buffer.allow_empty?).to be false + buffer_options[:allow_silent] = false + expect(buffer.allow_silent?).to be false end it 'defaults to false' do