Class: HttpLogger
- Inherits:
-
Object
- Object
- HttpLogger
- Defined in:
- lib/http_logger.rb
Overview
Usage:
require 'http_logger'
Setup logger
HttpLogger.logger = Logger.new('/tmp/all.log')
HttpLogger.log_headers = true
Do request
res = Net::HTTP.start(url.host, url.port) { |http|
http.request(req)
}
...
View the log
cat /tmp/all.log
Constant Summary collapse
- AUTHORIZATION_HEADER =
'Authorization'
Class Attribute Summary collapse
-
.collapse_body_limit ⇒ Object
Returns the value of attribute collapse_body_limit.
-
.colorize ⇒ Object
Returns the value of attribute colorize.
-
.ignore ⇒ Object
Returns the value of attribute ignore.
-
.level ⇒ Object
Returns the value of attribute level.
-
.log_headers ⇒ Object
Returns the value of attribute log_headers.
-
.log_request_body ⇒ Object
Returns the value of attribute log_request_body.
-
.log_response_body ⇒ Object
Returns the value of attribute log_response_body.
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.collapse_body_limit ⇒ Object
Returns the value of attribute collapse_body_limit.
28 29 30 |
# File 'lib/http_logger.rb', line 28 def collapse_body_limit @collapse_body_limit end |
.colorize ⇒ Object
Returns the value of attribute colorize.
33 34 35 |
# File 'lib/http_logger.rb', line 33 def colorize @colorize end |
.ignore ⇒ Object
Returns the value of attribute ignore.
34 35 36 |
# File 'lib/http_logger.rb', line 34 def ignore @ignore end |
.level ⇒ Object
Returns the value of attribute level.
35 36 37 |
# File 'lib/http_logger.rb', line 35 def level @level end |
.log_headers ⇒ Object
Returns the value of attribute log_headers.
29 30 31 |
# File 'lib/http_logger.rb', line 29 def log_headers @log_headers end |
.log_request_body ⇒ Object
Returns the value of attribute log_request_body.
30 31 32 |
# File 'lib/http_logger.rb', line 30 def log_request_body @log_request_body end |
.log_response_body ⇒ Object
Returns the value of attribute log_response_body.
31 32 33 |
# File 'lib/http_logger.rb', line 31 def log_response_body @log_response_body end |
.logger ⇒ Object
Returns the value of attribute logger.
32 33 34 |
# File 'lib/http_logger.rb', line 32 def logger @logger end |
Class Method Details
.deprecate_config(option) ⇒ Object
54 55 56 |
# File 'lib/http_logger.rb', line 54 def self.deprecate_config(option) warn "Net::HTTP.#{option} is deprecated. Use HttpLogger.#{option} instead." end |
.instance ⇒ Object
50 51 52 |
# File 'lib/http_logger.rb', line 50 def self.instance @instance ||= HttpLogger.new end |
.perform(*args, &block) ⇒ Object
46 47 48 |
# File 'lib/http_logger.rb', line 46 def self.perform(*args, &block) instance.perform(*args, &block) end |
Instance Method Details
#perform(http, request, request_body) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/http_logger.rb', line 58 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) end end end |