Sha256: e3adb34140997a9c0f9ff22ffd4816ff71ba98d277f809dcc6b2c6b6dd37b593

Contents?: true

Size: 962 Bytes

Versions: 17

Compression:

Stored size: 962 Bytes

Contents

require "savon/log_message"

module Savon
  class RequestLogger

    def initialize(globals)
      @globals = globals
    end

    def log(request, &http_request)
      log_request(request) if log?
      response = http_request.call
      log_response(response) if log?

      response
    end

    def logger
      @globals[:logger]
    end

    def log?
      @globals[:log]
    end

    private

    def log_request(request)
      logger.info  "SOAP request: #{request.url}"
      logger.info  headers_to_log(request.headers)
      logger.debug body_to_log(request.body)
    end

    def log_response(response)
      logger.info  "SOAP response (status #{response.code})"
      logger.debug body_to_log(response.body)
    end

    def headers_to_log(headers)
      headers.map { |key, value| "#{key}: #{value}" }.join(", ")
    end

    def body_to_log(body)
      LogMessage.new(body, @globals[:filters], @globals[:pretty_print_xml]).to_s
    end

  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
savon-2.9.0 lib/savon/request_logger.rb
savon-2.8.1 lib/savon/request_logger.rb
savon-2.8.0 lib/savon/request_logger.rb
savon-2.7.2 lib/savon/request_logger.rb
savon-2.7.1 lib/savon/request_logger.rb
savon-2.7.0 lib/savon/request_logger.rb
savon-2.6.0 lib/savon/request_logger.rb
savon-2.5.1 lib/savon/request_logger.rb
savon-2.5.0 lib/savon/request_logger.rb
savon_with_adapter-2.4.1 lib/savon/request_logger.rb
savon-2.4.0 lib/savon/request_logger.rb
savon-2.3.3 lib/savon/request_logger.rb
savon-2.3.2 lib/savon/request_logger.rb
savon-2.3.1 lib/savon/request_logger.rb
savon-ng-1.6-2.4.1 lib/savon/request_logger.rb
savon-ng-1.6-2.4.0 lib/savon/request_logger.rb
savon-2.3.0 lib/savon/request_logger.rb