Class: ConciseLogging::LogMiddleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ LogMiddleware

Returns a new instance of LogMiddleware.



3
4
5
# File 'lib/concise_logging/log_middleware.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/concise_logging/log_middleware.rb', line 7

def call(env)
  request = ActionDispatch::Request.new(env)
  Thread.current[:logged_ip] = request.env['HTTP_X_REAL_IP'] || request.ip
  @app.call(env)
ensure
  Thread.current[:logged_ip] = nil
end