Class: Savon::RequestLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/savon/request_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(globals) ⇒ RequestLogger

Returns a new instance of RequestLogger.



7
8
9
# File 'lib/savon/request_logger.rb', line 7

def initialize(globals)
  @globals = globals
end

Instance Method Details

#log(request, &http_request) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/savon/request_logger.rb', line 11

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

  response
end

#log?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/savon/request_logger.rb', line 23

def log?
  @globals[:log]
end

#log_headers?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/savon/request_logger.rb', line 27

def log_headers?
  @globals[:log_headers]
end

#log_request(request) ⇒ Object



30
31
32
33
34
35
# File 'lib/savon/request_logger.rb', line 30

def log_request(request)
  return unless log?
  logger.info  { "SOAP request: #{request.path}" }
  logger.info  { headers_to_log(request.headers) } if log_headers?
  logger.debug { body_to_log(request.body) }
end

#log_response(response) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/savon/request_logger.rb', line 37

def log_response(response)
  return response unless log?
  logger.info  { "SOAP response (status #{response.status})" }
  logger.debug { headers_to_log(response.headers) } if log_headers?
  logger.debug { body_to_log(response.body) }
  response
end

#loggerObject



19
20
21
# File 'lib/savon/request_logger.rb', line 19

def logger
  @globals[:logger]
end