Class: Mack::RunnerHelpers::RequestLogger

Inherits:
Base show all
Defined in:
lib/mack/runner_helpers/request_logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



7
8
9
# File 'lib/mack/runner_helpers/request_logger.rb', line 7

def end_time
  @end_time
end

#requests_per_secondObject (readonly)

Returns the value of attribute requests_per_second.



9
10
11
# File 'lib/mack/runner_helpers/request_logger.rb', line 9

def requests_per_second
  @requests_per_second
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



6
7
8
# File 'lib/mack/runner_helpers/request_logger.rb', line 6

def start_time
  @start_time
end

#total_timeObject (readonly)

Returns the value of attribute total_time.



8
9
10
# File 'lib/mack/runner_helpers/request_logger.rb', line 8

def total_time
  @total_time
end

Instance Method Details

#complete(request, response, cookies) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mack/runner_helpers/request_logger.rb', line 15

def complete(request, response, cookies)
  @end_time = Time.now
  @total_time = @end_time - @start_time
  @requests_per_second = (1 / @total_time).round
  if configatron.mack.log.detailed_requests
    msg = "\n\t[#{request.params[:method].to_s.upcase}] '#{request.path_info}'\n"
    msg << "\tSession ID: #{request.session.id}\n" if configatron.mack.use_sessions
    msg << "\tParameters: #{request.params}\n"
    msg << Mack::Utils::Ansi::Color.wrap(configatron.mack.log.colors.completed, "\tCompleted in #{@total_time} (#{@requests_per_second} reqs/sec) | #{response.status} (#{Mack::Utils::HttpStatusCodes.get(response.status)}) [#{request.full_host}]")
  else
    msg = "[#{request.request_method.upcase}] '#{request.path_info}' (#{total_time})"
  end
  Mack.logger.info(msg)
end

#start(request, response, cookies) ⇒ Object



11
12
13
# File 'lib/mack/runner_helpers/request_logger.rb', line 11

def start(request, response, cookies)
  @start_time = Time.now
end