Class: Inferno::Utils::Middleware::RequestLogger
- Inherits:
-
Object
- Object
- Inferno::Utils::Middleware::RequestLogger
- Defined in:
- lib/davinci_plan_net_test_kit/request_logger.rb
Instance Method Summary collapse
Instance Method Details
#log_request(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/davinci_plan_net_test_kit/request_logger.rb', line 23 def log_request(env) method = env['REQUEST_METHOD'] scheme = env['rack.url_scheme'] host = env['HTTP_HOST'] path = env['REQUEST_URI'] query = env['rack.request.query_string'] body = env['rack.input'] body = body.instance_of?(Puma::NullIO) ? nil : body.string query_string = query.blank? ? '' : "?#{query}" logger.info("#{method} #{scheme}://#{host}#{path}#{query_string}") return unless body.present? if body.length > 100 logger.info("#{body[0..100]}...") else logger.info(body) end end |
#log_response(response, start_time, end_time, exception = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/davinci_plan_net_test_kit/request_logger.rb', line 6 def log_response(response, start_time, end_time, exception = nil) elapsed = end_time - start_time status, _response_headers, body = response if response status, = response if exception logger.info("#{status} in #{elapsed.in_milliseconds} ms") return unless body.present? body = body.is_a?(Array) ? body.join : body if body.length > 100 logger.info("#{body[0..100]}...") else logger.info(body) end end |