Skip to content

Commit

Permalink
Merge pull request dwbutler#131 from AlexeyKrasnoperov/bugfix/allow-t…
Browse files Browse the repository at this point in the history
…ype-to-be-a-string-for-multi_logger-and-syslog

Allow type to be a string for multi_logger and syslog
  • Loading branch information
dwbutler authored Aug 30, 2017
2 parents 1da925e + fdf7953 commit 8cf7719
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/logstash-logger/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def self.extract_opts(*args)
def self.build_logger(opts)
formatter = Formatter.new(opts.delete(:formatter), customize_event: opts.delete(:customize_event))

logger = case opts[:type]
logger_type = opts[:type].is_a?(String) ? opts[:type].to_sym : opts[:type]
logger = case logger_type
when :multi_logger
build_multi_logger(opts)
when :syslog
Expand Down
1 change: 1 addition & 0 deletions logstash-logger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'pry'
gem.add_development_dependency 'wwtd'
gem.add_development_dependency 'appraisal'
gem.add_development_dependency 'rubocop', '0.4.6'
end
23 changes: 16 additions & 7 deletions spec/syslog_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
require 'logstash-logger'

describe LogStashLogger do
context "Syslog" do
let(:program_name) { "MyApp" }
let(:facility) { 128 } #Syslog::LOG_LOCAL0 }
let(:program_name) { 'MyApp' }
let(:facility) { 128 } #Syslog::LOG_LOCAL0 }

context 'Syslog' do
subject { LogStashLogger.new(type: :syslog, program_name: program_name, facility: facility) }
let(:syslog) { subject.class.class_variable_get(:@@syslog) }

it { is_expected.to be_a Syslog::Logger }

it "writes formatted messages to syslog" do
it 'writes formatted messages to syslog' do
expect(syslog).to receive(:log)
subject.info("test")
subject.info('test')
end

it "sets the syslog identity" do
it 'sets the syslog identity' do
expect(syslog.ident).to eq(program_name)
end

it "sets the default facility if supported" do
it 'sets the default facility if supported' do
expect(subject.facility).to eq(facility) if subject.respond_to?(:facility)
end
end

context 'When logger type is a string' do
subject { LogStashLogger.new(type: 'syslog', program_name: program_name, facility: facility) }

it 'creates syslog logger even if type is not a symbol' do
expect(subject).to be_a(LogStashLogger)
end
end
end

0 comments on commit 8cf7719

Please sign in to comment.