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.3"
Class Method Summary collapse
- .configuration ⇒ Object
- .configure(&block) ⇒ Object
- .instance ⇒ Object
- .perform(*args, &block) ⇒ Object
Instance Method Summary collapse
Class Method Details
.configuration ⇒ Object
29 30 31 |
# File 'lib/http_logger.rb', line 29 def self.configuration @configuration ||= Configuration.new end |
.configure(&block) ⇒ Object
33 34 35 |
# File 'lib/http_logger.rb', line 33 def self.configure(&block) block.call(configuration) end |
.instance ⇒ Object
42 43 44 |
# File 'lib/http_logger.rb', line 42 def self.instance @instance ||= HttpLogger.new end |
.perform(*args, &block) ⇒ Object
38 39 40 |
# File 'lib/http_logger.rb', line 38 def self.perform(*args, &block) instance.perform(*args, &block) end |
Instance Method Details
#perform(http, request, request_body) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/http_logger.rb', line 46 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, request_body) 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 |