Class: HttpLogger
- Inherits:
-
Object
- Object
- HttpLogger
- Defined in:
- lib/http_logger.rb,
lib/http_logger/version.rb,
lib/http_logger/configuration.rb
Overview
Usage:
require 'http_logger'
Setup logger
HttpLogger.configuration.logger = Logger.new('/tmp/all.log')
HttpLogger.configuration.log_headers = true
Do request
res = Net::HTTP.start(url.host, url.port) { |http|
http.request(req)
}
...
View the log
cat /tmp/all.log
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- AUTHORIZATION_HEADER =
'Authorization'
- VERSION =
"1.0.1"
Class Method Summary collapse
- .configuration ⇒ Object
- .configure(&block) ⇒ Object
- .instance ⇒ Object
- .perform(*args, &block) ⇒ Object
Instance Method Summary collapse
Class Method Details
.configuration ⇒ Object
28 29 30 |
# File 'lib/http_logger.rb', line 28 def self.configuration @configuration ||= Configuration.new end |
.configure(&block) ⇒ Object
32 33 34 |
# File 'lib/http_logger.rb', line 32 def self.configure(&block) block.call(configuration) end |
.instance ⇒ Object
41 42 43 |
# File 'lib/http_logger.rb', line 41 def self.instance @instance ||= HttpLogger.new end |
.perform(*args, &block) ⇒ Object
37 38 39 |
# File 'lib/http_logger.rb', line 37 def self.perform(*args, &block) instance.perform(*args, &block) end |
Instance Method Details
#perform(http, request, request_body) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/http_logger.rb', line 45 def perform(http, request, request_body) start_time = Time.now response = yield ensure if require_logging?(http, request) log_request_url(http, request, start_time) log_request_body(request) log_request_headers(request) if defined?(response) && response log_response_code(response) log_response_headers(response) log_response_body(response.body, binary_response?(response)) end end end |