Class: RrxLogging::Middleware
- Inherits:
-
Object
- Object
- RrxLogging::Middleware
- Defined in:
- lib/rrx_logging/middleware.rb
Overview
Replacement for default Rack logger to add pre-defined named tags instead of the default tag array
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
- #noise?(env) ⇒ Boolean
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
8 9 10 |
# File 'lib/rrx_logging/middleware.rb', line 8 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rrx_logging/middleware.rb', line 12 def call(env) request = ActionDispatch::Request.new(env) logger = env.fetch('action_dispatch.logger') { Rails.logger } if logger.is_a?(Logger) = { request_id: request.request_id } logger.(**) do if noise?(env) logger.silence_info { @app.call(env) } else @app.call(env) end end else @app.call(env) end end |
#noise?(env) ⇒ Boolean
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rrx_logging/middleware.rb', line 29 def noise?(env) Rails.configuration.request_noise_filters.any? do |filter| case filter when Regexp filter.match?(env['PATH_INFO']) when String env['PATH_INFO'].include? filter when Proc filter.call(env) else # Ignore false end end end |