Skip to content

Commit

Permalink
TECH-4787: delete :progname from context hash when we added it there
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDKelley committed Aug 31, 2020
1 parent d311699 commit 36154e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/contextual_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def add(arg_severity, arg1 = nil, arg2 = nil, **context) # Ruby will prefer to
if arg1.nil?
if block_given?
message = yield
progname = arg2 || context[:progname] || @progname
progname = arg2 || context.delete(:progname) || @progname
else
message = arg2
progname = @progname
Expand Down
10 changes: 9 additions & 1 deletion spec/lib/contextual_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,16 @@ def expect_log_line_to_be_written(log_line)
let(:message) { 'request: this is a test' }

it 'handles message block (inline context) with progname' do
expect_log_line_to_be_written(expected_log_hash.merge(progname: 'request').to_json)
formatter_args = []
logger.formatter = -> (*args) do
formatter_args = args
'"message"'
end
expect_log_line_to_be_written('"message"')
expect(logger.info('request', service: 'test_service') { 'this is a test' }).to eq(true)

expect(formatter_args[2]).to eq('request')
expect(formatter_args[3]).to eq(message: "this is a test", service: "test_service")
end
end

Expand Down

0 comments on commit 36154e4

Please sign in to comment.