1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-02-01 01:37:12 +00:00

Splat flows/adapters passed to Rackstash::Logger#initialize

This ensures that we are not unduely altering (i.e. flattening) adapter
specifications when creating the flows.
This commit is contained in:
Holger Just 2017-08-31 21:59:39 +02:00
parent 180faf9a55
commit 32e755396b
5 changed files with 16 additions and 20 deletions

View File

@ -19,7 +19,7 @@ module Rackstash
def initialize(*flows)
@flows = Concurrent::Array.new
flows.flatten.each do |flow|
flows.each do |flow|
add(flow)
end
end

View File

@ -57,10 +57,10 @@ module Rackstash
# By default we use {PROGNAME}.
# @param formatter [#call] the log formatter for each individual buffered
# line. See {#formatter} for details.
def initialize(flows, level: DEBUG, progname: PROGNAME, formatter: Formatter.new)
def initialize(*flows, level: DEBUG, progname: PROGNAME, formatter: Formatter.new)
@buffer_stack = Concurrent::ThreadLocalVar.new
@sink = Rackstash::Sink.new(flows)
@sink = Rackstash::Sink.new(*flows)
self.level = level
self.progname = progname
self.formatter = formatter

View File

@ -15,8 +15,8 @@ module Rackstash
# @param flows [Array<Flow, Object>, Flow, Adapters::Adapter, Object]
# an array of {Flow}s or a single {Flow}, respectivly object which can be
# used as a {Flow}'s adapter. See {Flow#initialize}.
def initialize(flows)
@flows = Rackstash::Flows.new(flows)
def initialize(*flows)
@flows = Rackstash::Flows.new(*flows)
@default_fields = {}
@default_tags = []

View File

@ -27,9 +27,6 @@ describe Rackstash::Flows do
it 'accepts a list of flows' do
raw_flows = Array.new(3) { a_flow }
list_with_array = described_class.new(raw_flows)
expect(list_with_array.size).to eql 3
list_with_splat = described_class.new(*raw_flows)
expect(list_with_splat.size).to eql 3
end

View File

@ -19,27 +19,27 @@ describe Rackstash::Sink do
flow
end
let(:flow) { a_flow }
let(:sink) { described_class.new(flow) }
let(:flows) { [a_flow] }
let(:sink) { described_class.new(*flows) }
describe 'initialize' do
# We deliberately use the real Rackstash::Flows class here to server as an
# integration test
it 'wraps a single flow in a flows list' do
expect(Rackstash::Flows).to receive(:new).with(flow)
expect(Rackstash::Flows).to receive(:new).with(*flows)
.and_call_original
sink = described_class.new(flow)
sink = described_class.new(*flows)
expect(sink.flows).to be_a Rackstash::Flows
expect(sink.flows.to_a).to eql [flow]
expect(sink.flows.to_a).to eql flows
end
it 'wraps multiple flows in a flows list' do
flows = [a_flow, a_flow]
expect(Rackstash::Flows).to receive(:new).with(flows)
expect(Rackstash::Flows).to receive(:new).with(*flows)
.and_call_original
sink = described_class.new(flows)
sink = described_class.new(*flows)
expect(sink.flows).to be_a Rackstash::Flows
expect(sink.flows.to_a).to eql flows
@ -111,19 +111,19 @@ describe Rackstash::Sink do
end
describe '#close' do
let(:flow) { [a_flow, a_flow] }
let(:flows) { [a_flow, a_flow] }
it 'calls close on all flows' do
expect(flow).to all receive(:close)
expect(flows).to all receive(:close)
expect(sink.close).to be_nil
end
end
describe '#reopen' do
let(:flow) { [a_flow, a_flow] }
let(:flows) { [a_flow, a_flow] }
it 'calls reopen on all flows' do
expect(flow).to all receive(:reopen)
expect(flows).to all receive(:reopen)
expect(sink.reopen).to be_nil
end
end
@ -134,7 +134,6 @@ describe Rackstash::Sink do
allow(flow).to receive(:write)
end
}
let(:sink) { described_class.new(flows) }
let(:buffer) { Rackstash::Buffer.new(sink) }
it 'merges default_fields and default_tags' do