Skip to content

Commit

Permalink
Log unknown severity levels at info level
Browse files Browse the repository at this point in the history
lenjador#add accepts `severity`. Fall back to `info` when the severity
cannot be mapped to a known "level" to not lose messages.

This was motivated by an external tool calling #add with 'any' severity.
  • Loading branch information
urmastalimaa committed Mar 13, 2024
1 parent ed543be commit bc8eb70
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/lenjador.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(adapter, level, preprocessors)
end

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

Expand Down
5 changes: 5 additions & 0 deletions spec/lenjador_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
lenjador.add('info', 'info-msg')
lenjador.add('warn', 'warn-msg')
end

it 'logs messages with unknown severity at info level' do
expect(adapter).to receive(:log).with(described_class::Severity::INFO, message: 'unknown-msg').ordered
lenjador.add('something-else', 'unknown-msg')
end
end

context 'when preprocessor defined' do
Expand Down

0 comments on commit bc8eb70

Please sign in to comment.