Class: Logworm::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/logworm_client/rack.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Rack

Returns a new instance of Rack.



6
7
8
9
10
11
12
13
14
# File 'lib/logworm_client/rack.rb', line 6

def initialize(app, options = {})
  @app = app
  
  @log_requests = (options[:donot_log_requests].nil? or options[:donot_log_requests] != true)
  @log_headers  = (options[:log_headers] and options[:log_headers] == true)
  @dev_logging  = (options[:log_in_development] and options[:log_in_development] == true)
  Logger.use_default_db
  @timeout = 1
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/logworm_client/rack.rb', line 16

def call(env)
  return @app.call(env) unless (ENV['RACK_ENV'] == 'production' or (ENV['RACK_ENV'] == 'development' and @dev_logging))

  Logger.start_cycle
  begin
    startTime = Time.now 
    status, response_headers, body = @app.call(env) 
    appTime = (Time.now - startTime) 
  ensure
    log_request(env, status, response_headers, appTime)
    return [status, response_headers, body] 
  end
end