Skip to content

Commit

Permalink
Merge pull request #89 from tilfin/feature/logger-new-with-formatter
Browse files Browse the repository at this point in the history
Logger.new supports formatter argument
  • Loading branch information
tilfin authored Aug 28, 2019
2 parents 5313adb + bf45032 commit ac77e85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ougai/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(*args)
@default_message = 'No message'
@exc_key = :err
@with_fields = {}
@formatter = create_formatter
@formatter = create_formatter if @formatter.nil?
end

class << self
Expand Down
18 changes: 18 additions & 0 deletions spec/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ def to_hash
end
end

describe '.new' do
context 'if formatter argument is not specified' do
it 'sets Bunyan to formatter attribute' do
expect(logger.formatter).to be_an(Ougai::Formatters::Bunyan)
end
end

if RUBY_VERSION > '2.4'
context 'if formatter argument is specified' do
it 'sets it to formatter attribute' do
a_formatter = Ougai::Formatters::Readable.new
a_logger = described_class.new(io, formatter: a_formatter)
expect(a_logger.formatter).to eq a_formatter
end
end
end
end

shared_examples 'log' do
context 'with message' do
it 'outputs valid' do
Expand Down

0 comments on commit ac77e85

Please sign in to comment.