Class: Rack::Httperflog::Logger
- Inherits:
-
Struct
- Object
- Struct
- Rack::Httperflog::Logger
- Defined in:
- lib/rack/httperflog.rb
Overview
Extracts the lines to log from the rack request and response and logs them to a file on log_path path.
Logger.new(“log/path”, :ping_urls, request, response)
- log_path
-
path to the log file to log the lines
- ping_urls
-
provide :ping_urls to perform an http get to each path found inside the body of the response. Provide any other value to avoid this check.
- request
-
a Rack::Request instance
- response
-
a Rack::Response instance
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#ping_urls ⇒ Object
Returns the value of attribute ping_urls.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#each {|"#{ request.path_info } method=#{ request.request_method.to_s.upcase }#{ form_data }\n"| ... } ⇒ Object
yields each line for the log.
-
#paths_to_log ⇒ Object
uses a HtmlPathsExtractor object to parse the response if it contains html, and extracts all the relevant paths.
-
#perform_logging ⇒ Object
Perform the logging of each log line to a file.
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file
61 62 63 |
# File 'lib/rack/httperflog.rb', line 61 def file @file end |
#ping_urls ⇒ Object
Returns the value of attribute ping_urls
61 62 63 |
# File 'lib/rack/httperflog.rb', line 61 def ping_urls @ping_urls end |
#request ⇒ Object
Returns the value of attribute request
61 62 63 |
# File 'lib/rack/httperflog.rb', line 61 def request @request end |
#response ⇒ Object
Returns the value of attribute response
61 62 63 |
# File 'lib/rack/httperflog.rb', line 61 def response @response end |
Instance Method Details
#each {|"#{ request.path_info } method=#{ request.request_method.to_s.upcase }#{ form_data }\n"| ... } ⇒ Object
yields each line for the log
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rack/httperflog.rb', line 70 def each return if response.server_error? || response.client_error? form_data = " contents=\"#{ Rack::Utils.build_query(request.params) }\"" if request.form_data? && !request.params.empty? yield "#{ request.path_info } method=#{ request.request_method.to_s.upcase }#{ form_data }\n" paths_to_log.each do |path| yield " #{ path }\n" if path != request.path_info && (ping_urls != :ping_urls || UrlHelper.url_status_is?("200", request.host, request.port, path)) end end |
#paths_to_log ⇒ Object
uses a HtmlPathsExtractor object to parse the response if it contains html, and extracts all the relevant paths.
83 84 85 |
# File 'lib/rack/httperflog.rb', line 83 def paths_to_log response.content_type =~ /html/ ? HtmlPathsExtractor.new(response.body).paths : Array.new end |
#perform_logging ⇒ Object
Perform the logging of each log line to a file
64 65 66 67 |
# File 'lib/rack/httperflog.rb', line 64 def perform_logging each { |line| file << line } file.flush end |