lib/syslogstash/logstash_writer.rb in syslogstash-0.1.5 vs lib/syslogstash/logstash_writer.rb in syslogstash-0.2.0
- old
+ new
@@ -8,12 +8,12 @@
# Create a new logstash writer.
#
# Give it a list of servers, and your writer will be ready to go.
# No messages will actually be *delivered*, though, until you call #run.
#
- def initialize(servers)
- @servers = servers.map { |s| URI(s) }
+ def initialize(servers, backlog)
+ @servers, @backlog = servers.map { |s| URI(s) }, @backlog
unless @servers.all? { |url| url.scheme == 'tcp' }
raise ArgumentError,
"Unsupported URL scheme: #{@servers.select { |url| url.scheme != 'tcp' }.join(', ')}"
end
@@ -25,10 +25,13 @@
# Add an entry to the list of messages to be sent to logstash. Actual
# message delivery will happen in a worker thread that is started with
# #run.
#
def send_entry(e)
- @entries_mutex.synchronize { @entries << e }
+ @entries_mutex.synchronize do
+ @entries << e
+ @entries.shift while @entries.length > @backlog
+ end
@worker.run if @worker
end
# Start sending messages to logstash servers. This method will return
# almost immediately, and actual message sending will occur in a