Class: MongodbLogger::RackMiddleware
- Inherits:
-
Object
- Object
- MongodbLogger::RackMiddleware
- Defined in:
- lib/mongodb_logger/rack_middleware.rb
Constant Summary collapse
- @@log_attributes_filter =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RackMiddleware
constructor
A new instance of RackMiddleware.
- #request_ip(request) ⇒ Object
Constructor Details
#initialize(app) ⇒ RackMiddleware
Returns a new instance of RackMiddleware.
10 11 12 |
# File 'lib/mongodb_logger/rack_middleware.rb', line 10 def initialize(app) @app = app end |
Class Method Details
.log_attributes_filter=(filter) ⇒ Object
6 7 8 |
# File 'lib/mongodb_logger/rack_middleware.rb', line 6 def self.log_attributes_filter=(filter) @@log_attributes_filter = filter end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mongodb_logger/rack_middleware.rb', line 18 def call(env) request = ::Rack::Request.new env path = request.path.split('/') log_attrs = { method: request.request_method, action: (path[2..-1] || []).join('/'), controller: path[1], path: request.path, url: request.url, params: request.params, ip: request_ip(request) } log_attrs = @@log_attributes_filter.call(log_attrs) if @@log_attributes_filter logger.mongoize(log_attrs) do return @app.call(env) end end |
#request_ip(request) ⇒ Object
14 15 16 |
# File 'lib/mongodb_logger/rack_middleware.rb', line 14 def request_ip(request) return request.env["REMOTE_ADDR"] end |