Class: Kiev::Rack::RequestLogger
- Inherits:
-
Object
- Object
- Kiev::Rack::RequestLogger
- Defined in:
- lib/kiev/rack/request_logger.rb
Constant Summary collapse
- ERROR_STATUS =
500- ERROR_HEADERS =
[].freeze
- ERROR_BODY =
[""].freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RequestLogger
constructor
A new instance of RequestLogger.
Constructor Details
#initialize(app) ⇒ RequestLogger
Returns a new instance of RequestLogger.
10 11 12 |
# File 'lib/kiev/rack/request_logger.rb', line 10 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/kiev/rack/request_logger.rb', line 14 def call(env) rescued_exception = nil began_at = Time.now.to_f request = ::Rack::Request.new(env) begin status, headers, body = @app.call(env) rescue Exception => e rescued_exception = e status = ERROR_STATUS headers = ERROR_HEADERS body = ERROR_BODY if defined?(ActionDispatch::ExceptionWrapper) status = ::ActionDispatch::ExceptionWrapper.status_code_for_exception(rescued_exception.class.name) end end response = ::Rack::Response.new(body, status, headers) rack_exception = log_rack_exception?(env[SINATRA_ERROR]) ? env[SINATRA_ERROR] : nil log_exception = RequestStore.store[:error] exception = rescued_exception || rack_exception || log_exception if exception || Config.instance.log_request_condition.call(request, response) Kiev.event( :request_finished, form_data( began_at: began_at, env: env, request: request, response: response, status: status, body: body, exception: exception ) ) end raise rescued_exception if rescued_exception [status, headers, body] end |