Class: RightSupport::Rack::LogSetter
- Defined in:
- lib/right_support/rack/log_setter.rb
Overview
A Rack middleware that logs information about every HTTP request received and every exception raised while processing a request.
The middleware can be configured to use its own logger, but defaults to using env for logging if it is present. If ‘rack.logger’ is not set, this middleware will set it before calling the next middleware. Therefore, RequestLogger can be used standalone to fulfill all logging needs, or combined with Rack::Logger or another middleware that provides logging services.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Add a logger to the Rack environment and call the next middleware.
-
#initialize(app, options = {}) ⇒ LogSetter
constructor
Initialize an instance of the middleware.
Constructor Details
#initialize(app, options = {}) ⇒ LogSetter
Initialize an instance of the middleware. For backward compatibility, the order of the logger and level parameters can be switched.
Parameters
- app(Object)
-
the inner application or middleware layer; must respond to #call
- logger(Logger)
-
(optional) the Logger object to use, defaults to a STDERR logger
- level(Integer)
-
(optional) a Logger level-constant (INFO, ERROR) to set the logger to
43 44 45 46 |
# File 'lib/right_support/rack/log_setter.rb', line 43 def initialize(app, ={}) @app = app @logger = [:logger] end |
Instance Method Details
#call(env) ⇒ Object
Add a logger to the Rack environment and call the next middleware.
Parameters
- env(Hash)
-
the Rack environment
Return
always returns whatever value is returned by the next layer of middleware
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/right_support/rack/log_setter.rb', line 55 def call(env) if @logger logger = @logger elsif env['rack.logger'] logger = env['rack.logger'] end env['rack.logger'] ||= logger return @app.call(env) end |