Class: NetObserver::Logger

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

Overview

NetObserver::Logger.new Logger.new STDOUT

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Logger

@param(Logger) logger which recieve informations about communication



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

def initialize(logger)
	@logger = logger
	Base.instance.add_observer(self)
end

Instance Method Details

#update(type, request, body, connection) ⇒ Object

methods to receive information about connection. Needed to allow itself to register agains Base



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/net_observer/logger.rb', line 20

def update(type, request, body, connection)
	case type
	when :response
		method = request.kind_of?(Net::HTTPSuccess) ? :info : :warn
		@logger.send method, "get response: #{request.inspect} with body #{body}"
	when :request
		port = ""
		port = ":#{connection.port}" if (connection.port.to_i != (connection.use_ssl? ? 443 : 80))
		url = "#{connection.use_ssl? ? "https" : "http"}://#{connection.address}#{port}"
		@logger.info "get request for url #{url}#{request.path} with method: #{request.method} with body #{request.body || body}"
	end
end