Class: VCR::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/vcr/util/logger.rb

Overview

Provides log message formatting helper methods.

Defined Under Namespace

Modules: Mixin, Null

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Logger

Returns a new instance of Logger.


5
6
7
# File 'lib/vcr/util/logger.rb', line 5

def initialize(stream)
  @stream = stream
end

Instance Method Details

#log(message, log_prefix, indentation_level = 0) ⇒ Object


9
10
11
12
13
# File 'lib/vcr/util/logger.rb', line 9

def log(message, log_prefix, indentation_level = 0)
  indentation = '  ' * indentation_level
  log_message = indentation + log_prefix + message
  @stream.puts log_message
end

#request_summary(request, request_matchers) ⇒ Object


15
16
17
18
19
20
# File 'lib/vcr/util/logger.rb', line 15

def request_summary(request, request_matchers)
  attributes = [request.method, request.uri]
  attributes << request.body.to_s[0, 80].inspect if request_matchers.include?(:body)
  attributes << request.headers.inspect          if request_matchers.include?(:headers)
  "[#{attributes.join(" ")}]"
end

#response_summary(response) ⇒ Object


22
23
24
# File 'lib/vcr/util/logger.rb', line 22

def response_summary(response)
  "[#{response.status.code} #{response.body[0, 80].inspect}]"
end