Class: Stump::AccessLog

Inherits:
Object
  • Object
show all
Defined in:
lib/stump/access_log.rb

Overview

The Middleware ensures that the logger provided (could be a standard Ruby Logger) gets called by Rack.

Constant Summary collapse

ACCESS_LOG_FORMAT =

Adheres to the Apache Common Log format: en.wikipedia.org/wiki/Common_Log_Format

%{%s - %s [%s] "%s %s%s %s" %d %0.4f \n}

Instance Method Summary collapse

Constructor Details

#initialize(app, logger) ⇒ AccessLog

Returns a new instance of AccessLog.



12
13
14
15
16
# File 'lib/stump/access_log.rb', line 12

def initialize(app, logger)
  @app = app
  @logger = logger || ::Logger.new(STDOUT, 'daily')
  @logger.level ||= 'info'
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/stump/access_log.rb', line 18

def call(env)
  env['rack.logger'] = @logger
  began_at = Time.now
  status, header, body = @app.call(env)
  log(env, status, began_at)
  [status, header, body]
end