Skip to content

Commit

Permalink
Show content-encoding in log message
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmorrison committed Jan 13, 2025
1 parent 3e2eba2 commit 0793fdd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/twirp/rails/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def call(env)

def log(env, status, response_headers, began_at)
content_type = response_headers["content-type"].presence
@logger.info("Twirp #{status} in #{duration_in_ms(began_at)}ms#{" as #{content_type}" if content_type}")
content_encoding = response_headers["content-encoding"].presence
@logger.info("Twirp #{status} in #{duration_in_ms(began_at)}ms#{" as #{content_type}" if content_type}#{" with content-encoding: #{content_encoding}" if content_encoding}")
end

def log_response_body(body)
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/haberdasher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def make_hat_success_request
expect(response.headers["vary"]).to eq("Accept-Encoding")
expect(response.headers["content-encoding"]).to eq("gzip")

expect(::Rails.logger).to have_received(:info).with(/Twirp 200 in \d+ms as application\/protobuf/)
expect(::Rails.logger).to have_received(:info).with(/Twirp 200 in \d+ms as application\/protobuf with content-encoding: gzip/)
expect(::Rails.logger).not_to have_received(:debug) # No debug output when gzipped
end

Expand Down

0 comments on commit 0793fdd

Please sign in to comment.