From 0114e1f47fdaaf08008ffa07d9a09f0ccdedff0a Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Tue, 17 Dec 2019 15:44:38 -0500 Subject: [PATCH] make ip logging more robust if request location cannot be retrieved from the http request, make sure the logging is handled gracefully --- app/services/qa/linked_data/request_header_service.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/services/qa/linked_data/request_header_service.rb b/app/services/qa/linked_data/request_header_service.rb index 20a5cbc6..412217ca 100644 --- a/app/services/qa/linked_data/request_header_service.rb +++ b/app/services/qa/linked_data/request_header_service.rb @@ -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