Class: Rack::GrayLogger::Middleware
- Inherits:
-
Object
- Object
- Rack::GrayLogger::Middleware
- Includes:
- GrayLogger::Support
- Defined in:
- lib/gray_logger/rack.rb
Instance Attribute Summary collapse
-
#gray_logger ⇒ Object
Returns the value of attribute gray_logger.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Methods included from GrayLogger::Support
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
9 10 11 |
# File 'lib/gray_logger/rack.rb', line 9 def initialize(app) @app = app end |
Instance Attribute Details
#gray_logger ⇒ Object
Returns the value of attribute gray_logger.
7 8 9 |
# File 'lib/gray_logger/rack.rb', line 7 def gray_logger @gray_logger end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gray_logger/rack.rb', line 13 def call(env) gray_logger = ::GrayLogger.proxy.gray_logger begin gray_logger.reset! status, headers, body = @app.call(env) rescue Exception => e gray_logger.log_exception(e) if gray_logger.automatic_logging? raise e ensure req = Rack::Request.new(env) if ::GrayLogger.configuration.automatic_logging? gray_logger.log_exception(env['rack.exception']) if env['rack.exception'] gray_logger.after_request_log.status_code = status.to_i gray_logger.after_request_log. = "Request: #{req.path} (#{status.to_i})" if gray_logger.after_request_log[:short_message].nil? gray_logger.flush else gray_logger.reset! end [status, headers, body] end end |