Class: ApiValve::Middleware::Logging::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/api_valve/middleware/logging.rb

Constant Summary collapse

INCOMING =
%(Started %s "%s" for %s at %s).freeze
COMPLETE =
%(Completed %s %s in %dms\n).freeze
URL_PARAMS =
%(URL params %s).freeze
REQUEST_PAYLOAD =
%(Request payload\n%s).freeze
REQUEST_HEADERS =
%(Request HTTP Headers %s).freeze
RESPONSE_HEADERS =
%(Response HTTP headers %s).freeze
RESPONSE_PAYLOAD =
%(Response payload\n%s).freeze
NON_STANDARD_REQUEST_HEADERS =
%w(CONTENT_LENGTH CONTENT_TYPE).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Log

Returns a new instance of Log.



17
18
19
# File 'lib/api_valve/middleware/logging.rb', line 17

def initialize(options = {})
  assign options
end

Instance Attribute Details

#began_atObject

Returns the value of attribute began_at.



15
16
17
# File 'lib/api_valve/middleware/logging.rb', line 15

def began_at
  @began_at
end

#envObject

Returns the value of attribute env.



15
16
17
# File 'lib/api_valve/middleware/logging.rb', line 15

def env
  @env
end

#response_headersObject

Returns the value of attribute response_headers.



15
16
17
# File 'lib/api_valve/middleware/logging.rb', line 15

def response_headers
  @response_headers
end

#response_payloadObject

Returns the value of attribute response_payload.



15
16
17
# File 'lib/api_valve/middleware/logging.rb', line 15

def response_payload
  @response_payload
end

#statusObject

Returns the value of attribute status.



15
16
17
# File 'lib/api_valve/middleware/logging.rb', line 15

def status
  @status
end

Instance Method Details

#after_requestObject



34
35
36
37
38
# File 'lib/api_valve/middleware/logging.rb', line 34

def after_request
  log_response_headers if Logging.log_response_headers
  log_response_payload if Logging.log_response_body
  log_response
end

#assign(options = {}) ⇒ Object



21
22
23
24
25
# File 'lib/api_valve/middleware/logging.rb', line 21

def assign(options = {})
  options.each do |k, v|
    public_send "#{k}=", v
  end
end

#before_requestObject



27
28
29
30
31
32
# File 'lib/api_valve/middleware/logging.rb', line 27

def before_request
  log_request
  log_url_params
  log_request_headers if Logging.log_request_headers
  log_request_payload if Logging.log_request_body
end