Method: LogStashLogger::Buffer#buffer_receive

Defined in:
lib/logstash-logger/buffer.rb

#buffer_receive(event, group = nil) ⇒ Object

Save an event for later delivery

Events are grouped by the (optional) group parameter you provide. Groups of events, plus the group name, are later passed to flush.

This call will block if :max_items has been reached.

Parameters:

  • event

    An item to buffer for flushing later.

  • group (defaults to: nil)

    Optional grouping key. All events with the same key will be passed to flush together, along with the grouping key itself.

See Also:

  • The overview has more information on grouping and flushing.


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/logstash-logger/buffer.rb', line 157

def buffer_receive(event, group=nil)
  buffer_initialize if ! @buffer_state

  # block if we've accumulated too many events
  while buffer_full? do
    on_full_buffer_receive(
      :pending => @buffer_state[:pending_count],
      :outgoing => @buffer_state[:outgoing_count]
    ) if @buffer_config[:has_on_full_buffer_receive]

    if @buffer_config[:drop_messages_on_full_buffer]
      reset_buffer
    else
      sleep 0.1
    end
  end

  @buffer_state[:pending_mutex].synchronize do
    @buffer_state[:pending_items][group] << event
    @buffer_state[:pending_count] += 1
  end

  if @buffer_config[:autoflush]
    buffer_flush(force: true)
  end
end