Class: AccessWatch::Logger
- Inherits:
-
Object
- Object
- AccessWatch::Logger
- Defined in:
- lib/access_watch/logger.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #extract_http_headers(headers) ⇒ Object
- #format_header_name(name) ⇒ Object
-
#initialize(config) ⇒ Logger
constructor
A new instance of Logger.
- #record(request, response) ⇒ Object
Constructor Details
#initialize(config) ⇒ Logger
Returns a new instance of Logger.
5 6 7 |
# File 'lib/access_watch/logger.rb', line 5 def initialize(config) @client = AccessWatch::Client.new(config) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/access_watch/logger.rb', line 3 def client @client end |
Instance Method Details
#extract_http_headers(headers) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/access_watch/logger.rb', line 27 def extract_http_headers(headers) headers.reduce({}) do |hash, (name, value)| if name.index("HTTP_") == 0 && name != "HTTP_COOKIE" hash[format_header_name(name)] = value end hash end end |
#format_header_name(name) ⇒ Object
36 37 38 |
# File 'lib/access_watch/logger.rb', line 36 def format_header_name(name) name.sub(/^HTTP_/, '').sub("_", " ").titleize.sub(" ", "-") end |
#record(request, response) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/access_watch/logger.rb', line 9 def record(request, response) post_request( time: Time.now.utc, address: request.remote_ip, host: request.host, request: { protocol: request.headers["Version"], method: request.method, scheme: URI(request.original_url).scheme, host: request.host, port: request.port, url: request.original_fullpath, headers: extract_http_headers(request.headers) }, response: {status: response.status}, ) end |