Class: LoggingHttpClient
- Inherits:
-
Io::Flow::V0::HttpClient::DefaultHttpHandler
- Object
- Io::Flow::V0::HttpClient::HttpHandler
- Io::Flow::V0::HttpClient::DefaultHttpHandler
- LoggingHttpClient
- Defined in:
- lib/logging_http_client.rb
Instance Method Summary collapse
- #execute(request) ⇒ Object
-
#initialize(base_uri, path) ⇒ LoggingHttpClient
constructor
A new instance of LoggingHttpClient.
Methods inherited from Io::Flow::V0::HttpClient::DefaultHttpHandler
Methods inherited from Io::Flow::V0::HttpClient::HttpHandler
Constructor Details
#initialize(base_uri, path) ⇒ LoggingHttpClient
Returns a new instance of LoggingHttpClient.
6 7 8 9 |
# File 'lib/logging_http_client.rb', line 6 def initialize(base_uri, path) super(base_uri) @logger = Logger.new(path) end |
Instance Method Details
#execute(request) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/logging_http_client.rb', line 11 def execute(request) original_open = client.open_timeout original_read = client.read_timeout start_time = Time.now.utc.round(10) @logger.info "start %s %s" % [request.method, request.path] if request.path.start_with?("/organizations") # Contrived example to show how client settings can be adjusted client.open_timeout = 60 client.read_timeout = 60 end begin super ensure client.open_timeout = original_open client.read_timeout = original_read end_time = Time.now.utc.round(10) duration = ((end_time - start_time)*1000).round(0) @logger.info "complete %s %s %s ms" % [request.method, request.path, duration] end end |