Class: HttpEventLogger::Logger

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Logger

Returns a new instance of Logger.


12
13
14
15
16
# File 'lib/http_event_logger/logger.rb', line 12

def initialize(options={})
  @logger            = options[:logger]            || DEFAULT_LOGGER
  @severity          = options[:severity]          || DEFAULT_SEVERITY
  @blacklist_pattern = options[:blacklist_pattern] || nil
end

Instance Method Details

#connected(connection) ⇒ Object


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

def connected(connection)
  log "[#{connection.uri}] Connected"
end

#logs?(uri) ⇒ Boolean

Returns:

  • (Boolean)

18
19
20
# File 'lib/http_event_logger/logger.rb', line 18

def logs?(uri)
  @blacklist_pattern.nil? || @blacklist_pattern !~ uri
end

#received(response) ⇒ Object


32
33
34
35
36
37
# File 'lib/http_event_logger/logger.rb', line 32

def received(response)
  log "[#{response.base_uri}] Benchmark: #{response.time_taken_in_seconds} seconds"
  log "[#{response.base_uri}] Received - Status: #{response.status}"
  log "[#{response.base_uri}] Received - Headers: #{response.headers}"
  log "[#{response.base_uri}] Received - Body:#{response.body_with_formatting}"
end

#sent(request) ⇒ Object


26
27
28
29
30
# File 'lib/http_event_logger/logger.rb', line 26

def sent(request)
  log "[#{request.base_uri}] Sent - #{request.method} #{request.uri}"
  log "[#{request.base_uri}] Sent - Headers: #{request.headers}"
  log "[#{request.base_uri}] Sent - Body: #{request.body}" if request.body.present?
end