Skip to content

Commit

Permalink
Support logger.add
Browse files Browse the repository at this point in the history
Ruby's logger has a add method that supports severity at the first
argument position. Conform to Ruby's logger and provide a similar "add"
method. This supports providing a Lenjador logger to external tools that
call "#add" on the provided logger.

MSG-816
  • Loading branch information
urmastalimaa committed Mar 12, 2024
1 parent 188a14b commit 46444f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/lenjador.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def initialize(adapter, level, preprocessors)
@preprocessors = preprocessors
end

def add(severity, *args, &block)
level = SEV_LABEL.index(severity.to_s)
log(level, *args, &block)
end

def debug(*args, &block)
log(Severity::DEBUG, *args, &block)
end
Expand Down
14 changes: 14 additions & 0 deletions spec/lenjador_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
end
end

describe '#add' do
let(:adapter) { double }
let(:lenjador) { described_class.new(adapter, Lenjador::Severity::INFO, []) }

it 'logs with severity' do
expect(adapter).to receive(:log).with(described_class::Severity::INFO, message: 'info-msg').ordered
expect(adapter).to receive(:log).with(described_class::Severity::WARN, message: 'warn-msg').ordered

lenjador.add('debug', 'debug-msg')
lenjador.add('info', 'info-msg')
lenjador.add('warn', 'warn-msg')
end
end

context 'when preprocessor defined' do
let(:lenjador) { described_class.new(adapter, level, [preprocessor]) }
let(:adapter) { double }
Expand Down

0 comments on commit 46444f0

Please sign in to comment.