Class: Gemstar::RequestLogger

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

Instance Method Summary collapse

Constructor Details

#initialize(app, io: $stderr) ⇒ RequestLogger

Returns a new instance of RequestLogger.



3
4
5
6
# File 'lib/gemstar/request_logger.rb', line 3

def initialize(app, io: $stderr)
  @app = app
  @io = io
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/gemstar/request_logger.rb', line 8

def call(env)
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  status, headers, body = @app.call(env)
  log_request(env, status, started_at)
  [status, headers, body]
rescue StandardError => e
  log_request(env, 500, started_at, error: e)
  raise
end