Class: HTTParty::Logger::CurlLogger
- Inherits:
-
Object
- Object
- HTTParty::Logger::CurlLogger
- Defined in:
- lib/httparty/logger/curl_logger.rb
Overview
:nodoc:
Constant Summary collapse
- TAG_NAME =
HTTParty.name
- OUT =
">"
- IN =
"<"
Instance Attribute Summary collapse
-
#current_time ⇒ Object
Returns the value of attribute current_time.
-
#level ⇒ Object
Returns the value of attribute level.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #format(request, response) ⇒ Object
-
#initialize(logger, level) ⇒ CurlLogger
constructor
A new instance of CurlLogger.
- #print(time, direction, line) ⇒ Object
Constructor Details
#initialize(logger, level) ⇒ CurlLogger
Returns a new instance of CurlLogger.
10 11 12 13 |
# File 'lib/httparty/logger/curl_logger.rb', line 10 def initialize(logger, level) @logger = logger @level = level.to_sym end |
Instance Attribute Details
#current_time ⇒ Object
Returns the value of attribute current_time.
8 9 10 |
# File 'lib/httparty/logger/curl_logger.rb', line 8 def current_time @current_time end |
#level ⇒ Object
Returns the value of attribute level.
8 9 10 |
# File 'lib/httparty/logger/curl_logger.rb', line 8 def level @level end |
#logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'lib/httparty/logger/curl_logger.rb', line 8 def logger @logger end |
Instance Method Details
#format(request, response) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/httparty/logger/curl_logger.rb', line 15 def format(request, response) = [] time = Time.now.strftime("%Y-%m-%d %H:%M:%S %z") http_method = request.http_method.name.split("::").last.upcase path = request.path.to_s << print(time, OUT, "#{http_method} #{path}") if request.[:headers] && request.[:headers].size > 0 request.[:headers].each do |k, v| << print(time, OUT, "#{k}: #{v}") end end << print(time, OUT, request.raw_body) << print(time, OUT, "") << print(time, IN, "HTTP/#{response.http_version} #{response.code}") headers = response.respond_to?(:headers) ? response.headers : response response.each_header do |response_header| << print(time, IN, "#{response_header.capitalize}: #{headers[response_header]}") end << print(time, IN, "\n#{response.body}") @logger.send @level, .join("\n") end |
#print(time, direction, line) ⇒ Object
43 44 45 |
# File 'lib/httparty/logger/curl_logger.rb', line 43 def print(time, direction, line) "[#{TAG_NAME}] [#{time}] #{direction} #{line}" end |