Skip to content

Commit

Permalink
Merge pull request #129 from swiftype/alechoey/configurable_logger_class
Browse files Browse the repository at this point in the history
Allow user configuration of the logger class
  • Loading branch information
dwbutler authored Aug 30, 2017
2 parents a40fbb5 + e733db7 commit 2f84d1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/logstash-logger/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ def self.build_logger(opts)
private

def self.build_default_logger(opts)
logger_class = opts.delete(:logger_class) || ::Logger
device = Device.new(opts)
::Logger.new(device).tap do |logger|
logger_class.new(device).tap do |logger|
logger.instance_variable_set(:@device, device)
extend_logger(logger)
end
Expand Down
16 changes: 12 additions & 4 deletions spec/constructor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
require 'logstash-logger'

describe LogStashLogger do
describe ".new" do
it "returns a Logger instance" do
describe '.new' do
it 'returns a Logger instance' do
expect(LogStashLogger.new(type: :stdout)).to be_a ::Logger
end

context "type: :multi_logger" do
context 'type: :multi_logger' do
it "returns an instance of LogStashLogger::MultiLogger" do
expect(LogStashLogger.new(type: :multi_logger)).to be_a LogStashLogger::MultiLogger
end

it "merges top level configuration into each logger" do
it 'merges top level configuration into each logger' do
logger = LogStashLogger.new(type: :multi_logger, port: 1234, outputs: [ { type: :tcp }, { type: :udp } ])
logger.loggers.each do |logger|
expect(logger.device.port).to eq(1234)
end
end
end

context 'logger_class: CustomLogger' do
class CustomLogger < Logger; end

it 'should create a logger of the specified class' do
expect(LogStashLogger.new(type: :stdout, :logger_class => CustomLogger)).to be_a CustomLogger
end
end
end
end

0 comments on commit 2f84d1a

Please sign in to comment.