diff --git a/CHANGELOG.md b/CHANGELOG.md index bfea451e..ba94eda8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +UPCOMING +-------- + - Improved the logging format to include more information and increase human readability. + 30.0.0 ------ - Compatibility with v17.1 of the API: https://developers.google.com/google-ads/api/docs/release-notes diff --git a/lib/google/ads/google_ads/interceptors/logging_interceptor.rb b/lib/google/ads/google_ads/interceptors/logging_interceptor.rb index 24f0f1ef..8389ac57 100644 --- a/lib/google/ads/google_ads/interceptors/logging_interceptor.rb +++ b/lib/google/ads/google_ads/interceptors/logging_interceptor.rb @@ -57,7 +57,7 @@ def request_response(request:, call:, method:, metadata: {}) response = yield @logger.info { build_summary_message(request, call, method, false) } - @logger.debug { build_request_message(metadata, request) } + @logger.debug { build_request_message(request, call, method, metadata) } @logger.debug { build_success_response_message(response) } if response.respond_to?(:partial_failure_error) && response.partial_failure_error @logger.debug { build_partial_failure_message(response) } @@ -65,7 +65,7 @@ def request_response(request:, call:, method:, metadata: {}) response rescue Exception @logger.warn { build_summary_message(request, call, method, true) } - @logger.info { build_request_message(metadata, request) } + @logger.info { build_request_message(request, call, method, metadata) } @logger.info { build_error_response_message } raise end @@ -77,7 +77,7 @@ def server_streamer(request:, call:, method:, metadata: {}) responses = yield Enumerator.new do |y| responses.each { |response| - @logger.debug { build_request_message(metadata, request) } + @logger.debug { build_request_message(request, call, method, metadata) } @logger.debug { build_success_response_message(response) } if response.respond_to?(:partial_failure_error) && response.partial_failure_error @logger.debug { build_partial_failure_message(response) } @@ -103,7 +103,7 @@ def server_streamer(request:, call:, method:, metadata: {}) def handle_error(request, call, method, metadata) @logger.warn { build_summary_message(request, call, method, true) } - @logger.info { build_request_message(metadata, request) } + @logger.info { build_request_message(request, call, method, metadata) } @logger.info { build_error_response_message } raise end @@ -155,10 +155,11 @@ def error_details(exception) end def build_success_response_message(response) - "Incoming response: Payload: #{sanitize_message(response).to_json}" + "\nResponse\n--------\n" \ + "Response: #{sanitize_message(response).to_json}" end - def build_request_message(metadata, request) + def build_request_message(request, call, method, metadata) # calling #to_json on some protos (specifically those with non-UTF8 # encodable byte values) causes a segfault, however #inspect works # so we check if the proto contains a bytevalue, and if it does @@ -168,8 +169,11 @@ def build_request_message(metadata, request) else sanitize_message(request).to_json end - "Outgoing request: Headers: #{sanitize_headers(metadata).to_json} " \ - "Payload: #{request_inspect}" + "\nRequest\n-------\n" \ + "Method: #{method}\n" \ + "Host: #{call.instance_variable_get(:@wrapped).instance_variable_get(:@peer)}\n" \ + "Headers: #{sanitize_headers(metadata).to_json}\n" \ + "Request: #{request_inspect}" end def sanitize_headers(metadata)