Skip to content

Commit

Permalink
make ip logging more robust
Browse files Browse the repository at this point in the history
if request location cannot be retrieved from the http request, make sure the logging is handled gracefully
  • Loading branch information
elrayle committed Dec 17, 2019
1 parent 926d9e6 commit 0114e1f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/services/qa/linked_data/request_header_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ def content_type_for_format
private

def log_request
gc = request.location
msg = "******** #{request.path_parameters[:action].upcase}"
msg += " from IP #{request.ip} in {city: #{gc.city}, state: #{gc.state}, country: #{gc.country}}" unless Qa.config.suppress_ip_data_from_log
unless Qa.config.suppress_ip_data_from_log
gc = request.respond_to?(:location) ? request.location : nil
city = gc.nil? ? "UNKNOWN" : gc.city
state = gc.nil? ? "UNKNOWN" : gc.state
country = gc.nil? ? "UNKNOWN" : gc.country
msg += " from IP #{request.ip} in {city: #{city}, state: #{state}, country: #{country}}"
end
Rails.logger.info(msg)
end

Expand Down

0 comments on commit 0114e1f

Please sign in to comment.