Class: LogParser::LogEntry
- Inherits:
-
Object
- Object
- LogParser::LogEntry
- Defined in:
- lib/production_log/parser.rb
Overview
LogEntry contains a summary of log data for a single request.
Instance Attribute Summary collapse
-
#db_time ⇒ Object
readonly
Total database time.
-
#format ⇒ Object
readonly
(optional) format of request such as csv, xml, json…
-
#ip ⇒ Object
readonly
Requesting IP.
-
#page ⇒ Object
readonly
Controller and action for this request.
-
#queries ⇒ Object
readonly
Array of SQL queries containing query type and time taken.
-
#render_time ⇒ Object
readonly
Total render time.
-
#request_time ⇒ Object
readonly
Total request time, including database, render and other.
-
#time ⇒ Object
readonly
Time the request was made.
-
#verb ⇒ Object
readonly
(mandatory) http method #PUT/GET/POST, etc.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#initialize(entry) ⇒ LogEntry
constructor
Creates a new LogEntry from the log data in
entry
. -
#parse(entry) ⇒ Object
Extracts log data from
entry
, which is an Array of lines from the same request.
Constructor Details
#initialize(entry) ⇒ LogEntry
Creates a new LogEntry from the log data in entry
.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/production_log/parser.rb', line 58 def initialize(entry) @page = nil @format = nil #like json,xml,csv - part of page. @verb = nil #PUT/GET/POST/etc, http request method @ip = nil @time = nil @queries = [] @request_time = 0 @render_time = 0 @db_time = 0 @in_component = 0 parse entry end |
Instance Attribute Details
#db_time ⇒ Object (readonly)
Total database time
53 54 55 |
# File 'lib/production_log/parser.rb', line 53 def db_time @db_time end |
#format ⇒ Object (readonly)
(optional) format of request such as csv, xml, json…
21 22 23 |
# File 'lib/production_log/parser.rb', line 21 def format @format end |
#ip ⇒ Object (readonly)
Requesting IP
27 28 29 |
# File 'lib/production_log/parser.rb', line 27 def ip @ip end |
#page ⇒ Object (readonly)
Controller and action for this request
20 21 22 |
# File 'lib/production_log/parser.rb', line 20 def page @page end |
#queries ⇒ Object (readonly)
Array of SQL queries containing query type and time taken. The complete text of the SQL query is not saved to reduct memory usage.
38 39 40 |
# File 'lib/production_log/parser.rb', line 38 def queries @queries end |
#render_time ⇒ Object (readonly)
Total render time.
48 49 50 |
# File 'lib/production_log/parser.rb', line 48 def render_time @render_time end |
#request_time ⇒ Object (readonly)
Total request time, including database, render and other.
43 44 45 |
# File 'lib/production_log/parser.rb', line 43 def request_time @request_time end |
#time ⇒ Object (readonly)
Time the request was made
32 33 34 |
# File 'lib/production_log/parser.rb', line 32 def time @time end |
#verb ⇒ Object (readonly)
(mandatory) http method #PUT/GET/POST, etc
22 23 24 |
# File 'lib/production_log/parser.rb', line 22 def verb @verb end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/production_log/parser.rb', line 126 def ==(other) # :nodoc: other.class == self.class and other.page == self.page and other.format == self.format and other.verb == self.verb and other.ip == self.ip and other.time == self.time and other.queries == self.queries and other.request_time == self.request_time and other.render_time == self.render_time and other.db_time == self.db_time end |
#parse(entry) ⇒ Object
Extracts log data from entry
, which is an Array of lines from the same request.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/production_log/parser.rb', line 77 def parse(entry) entry = entry.split(/\n/) if String === entry entry.each do |line| case line when /^Parameters/, /^Cookie set/, /^Rendering/, /^Redirected/ then # nothing when /^Processing ([\S]+)(?: to ([\S]+))? \(for (.+) at (.*)\)(?: \[([\S+]+)\])?/ then next if @in_component > 0 @page = $1 @format = $2 @ip = $3 @time = $4 @verb = $5 # Rails 2.3 when /Completed in (\d+)ms \(View: (\d*), DB: (\d*)\)/ then next if @in_component > 0 @request_time = $1.to_f / 1000 @render_time = $2.to_f / 1000 @db_time = $3.to_f / 1000 when /Completed in ([\S]+)ms \(DB: ([\S]*)\)/ then # Redirect next if @in_component > 0 @request_time = $1.to_f / 1000 @render_time = 0 @db_time = $2.to_f / 1000 # Rails < 2.3 when /^Completed in ([\S]+) .+ Rendering: ([\S]+) .+ DB: ([\S]+)/ then next if @in_component > 0 @request_time = $1.to_f @render_time = $2.to_f @db_time = $3.to_f when /^Completed in ([\S]+) .+ DB: ([\S]+)/ then # Redirect next if @in_component > 0 @request_time = $1.to_f @render_time = 0 @db_time = $2.to_f when /(.+?) \(([^)]+)\) / then @queries << [$1, $2.to_f] when /^Start rendering component / then @in_component += 1 when /^End of component rendering$/ then @in_component -= 1 when /^Fragment hit: / then else # noop # raise "Can't handle #{line.inspect}" if $TESTING end end end |