Class: FunApi::Middleware::RequestLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/funapi/middleware/request_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, **options) ⇒ RequestLogger

Returns a new instance of RequestLogger.



6
7
8
9
10
# File 'lib/funapi/middleware/request_logger.rb', line 6

def initialize(app, **options)
  @app = app
  @logger = options[:logger] || Logger.new($stdout)
  @level = options[:level] || :info
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/funapi/middleware/request_logger.rb', line 12

def call(env)
  start = Time.now
  status, headers, body = @app.call(env)
  duration = Time.now - start

  log_request(env, status, duration)

  [status, headers, body]
end