Class: Beaver::Parsers::Rails
- Defined in:
- lib/beaver/parsers/rails.rb
Overview
Parser for Rails log entries. See the Request class for more log entry attributes.
Constant Summary collapse
- REGEX_MATCH =
:nodoc:
/^Started [A-Z]+/
- REGEX_METHOD =
:nodoc:
/^Started ([A-Z]+)/
- REGEX_METHOD_OVERRIDE =
:nodoc:
/"_method"=>"([A-Za-z]+)"/
- REGEX_CONTROLLER =
:nodoc:
/Processing by (\w+Controller)#/
- REGEX_ACTION =
:nodoc:
/Processing by \w+Controller#(\w+) as/
- REGEX_COMPLETED =
:nodoc:
/Completed (\d+)/
- REGEX_PATH =
:nodoc:
/^Started [A-Z]+ "([^"]+)"/
- REGEX_PARAMS_STR =
:nodoc:
/ Parameters: (\{.+\})$/
- REGEX_IP =
:nodoc:
/" for ([a-zA-Z0-9:.]+) at /
- REGEX_FORMAT =
:nodoc:
/Processing by .+ as (\w+)$/
- REGEX_MS =
:nodoc:
/ in (\d+\.?\d*)ms/
- REGEX_TAGS =
:nodoc:
/^(\[.+\] )+/
- REGEX_TAG =
:nodoc:
/\[([^\]]+)\] /
- REGEX_TIME =
Depending on the version of Rails, the time format may be wildly different
/ at ([a-z0-9:\+\- ]+)$/i
Constants inherited from Request
Request::BLANK_HASH, Request::BLANK_STR
Instance Method Summary collapse
-
#action ⇒ Object
Returns the class name of the Rails controller action that handled the request.
-
#completed? ⇒ Boolean
Returns true if/when we have the final line of the multi-line Rails request.
-
#controller ⇒ Object
Returns the class name of the Rails controller that handled the request.
-
#format ⇒ Object
Returns the responses format (html, json, etc).
- #invalid? ⇒ Boolean
-
#ms ⇒ Object
Returns the number of milliseconds it took for the request to complete.
-
#tags ⇒ Object
Returns an array of tags associated with the request.
-
#tags_str ⇒ Object
Returns the tags string associated with the request (e.g. “[tag1] [tag2] ”).
Methods inherited from Request
#<<, #date, #final!, #final?, for, inherited, #initialize, #ip, match?, #method, #params, #params_str, #path, #skip!, #status, #time, #to_s
Constructor Details
This class inherits a constructor from Beaver::Request
Instance Method Details
#action ⇒ Object
Returns the class name of the Rails controller action that handled the request
36 37 38 |
# File 'lib/beaver/parsers/rails.rb', line 36 def action @action ||= REGEX_ACTION.match(@data) ? $1.to_sym : :unknown end |
#completed? ⇒ Boolean
Returns true if/when we have the final line of the multi-line Rails request
26 27 28 |
# File 'lib/beaver/parsers/rails.rb', line 26 def completed? REGEX_COMPLETED =~ @data end |
#controller ⇒ Object
Returns the class name of the Rails controller that handled the request
31 32 33 |
# File 'lib/beaver/parsers/rails.rb', line 31 def controller @controller ||= REGEX_CONTROLLER.match(@data) ? $1 : BLANK_STR end |
#format ⇒ Object
Returns the responses format (html, json, etc)
41 42 43 |
# File 'lib/beaver/parsers/rails.rb', line 41 def format @format ||= REGEX_FORMAT.match(@data) ? $1.downcase.to_sym : :unknown end |
#invalid? ⇒ Boolean
21 22 23 |
# File 'lib/beaver/parsers/rails.rb', line 21 def invalid? @data.scan(REGEX_MATCH).size > 1 end |
#ms ⇒ Object
Returns the number of milliseconds it took for the request to complete
46 47 48 |
# File 'lib/beaver/parsers/rails.rb', line 46 def ms @ms ||= REGEX_MS.match(@data) ? $1.to_f : 0 end |
#tags ⇒ Object
Returns an array of tags associated with the request
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/beaver/parsers/rails.rb', line 56 def @tags ||= if t = = t.scan(REGEX_TAG) .flatten! .uniq! .map! &:downcase else [] end end |
#tags_str ⇒ Object
Returns the tags string associated with the request (e.g. “[tag1] [tag2] ”)
51 52 53 |
# File 'lib/beaver/parsers/rails.rb', line 51 def @tags_str ||= REGEX_TAGS.match(@data) ? $1 : nil end |