Class: Logfoo::LogMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/logfoo/middlewares/log_middleware.rb

Constant Summary collapse

FORMAT =
%{%s "%s %s%s %s" %d %s %0.4f}
IGNORED =
%w{ /health /_ping }

Instance Method Summary collapse

Constructor Details

#initialize(app, log = nil) ⇒ LogMiddleware



9
10
11
12
# File 'lib/logfoo/middlewares/log_middleware.rb', line 9

def initialize(app, log = nil)
  @log = log || Logfoo.get_logger('Rack')
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/logfoo/middlewares/log_middleware.rb', line 14

def call(env)
  began_at = Time.now
  status, header, body = @app.call(env)
  header = Rack::Utils::HeaderHash.new(header)
  body   = Rack::BodyProxy.new(body) { log(env, status, header, began_at) }
  [status, header, body]
end