class HTTP::Features::Logging
Log requests and responses. Request
verb and uri, and Response
status are logged at ‘info`, and the headers and bodies of both are logged at `debug`. Be sure to specify the logger when enabling the feature:
HTTP.use(logging: {logger: Logger.new(STDOUT)}).get("https://example.com/")
Attributes
Public Class Methods
Source
# File lib/http/features/logging.rb, line 28 def initialize(logger: NullLogger.new) @logger = logger end
Public Instance Methods
Source
# File lib/http/features/logging.rb, line 32 def wrap_request(request) logger.info { "> #{request.verb.to_s.upcase} #{request.uri}" } logger.debug { "#{stringify_headers(request.headers)}\n\n#{request.body.source}" } request end
Source
# File lib/http/features/logging.rb, line 39 def wrap_response(response) logger.info { "< #{response.status}" } logger.debug { "#{stringify_headers(response.headers)}\n\n#{response.body}" } response end
Private Instance Methods
Source
# File lib/http/features/logging.rb, line 48 def stringify_headers(headers) headers.map { |name, value| "#{name}: #{value}" }.join("\n") end