rawk_log 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,10 +20,13 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install rawk_log
22
22
 
23
- This will
23
+ ### Patching logger
24
24
 
25
- 1. add the rawk_log command
26
- 2. adjust Logger and ActiveSupport::BufferedLogger to append " (pid:#{$$})" to log lines so urls can be related to their controller and method (if added to the Gemfile)
25
+ To enable reporting by controller#action add the following to at the end of the environment.rb file:
26
+
27
+ require 'rawk_log/patch_logger'
28
+
29
+ This will patch Logger and/or ActiveSupport::BufferedLogger to append " (pid:#{$$})" to each line of the log file.
27
30
 
28
31
  ## Usage
29
32
 
@@ -1,11 +1,12 @@
1
1
  require 'date'
2
2
  require 'rawk_log/stat'
3
3
  require 'rawk_log/stat_hash'
4
+ require "rawk_log/version"
4
5
 
5
6
  module RawkLog
6
7
  class Command
7
- HELP = "\nRAWK - Rail's Analyzer With Klass\n"+
8
- "Created by Chris Hobbs of Spongecell, LLC\n"+
8
+ HELP = "\nRAWK_LOG - Rail's Analyzer With Klass for log files v#{VERSION}\n"+
9
+ "Created by Chris Hobbs of Spongecell, LLC, updated by Ian Heggie and others\n"+
9
10
  "This tool gives statistics for Ruby on Rails log files. The times for each request are grouped and totals are displayed. "+
10
11
  "If process ids are present in the log files then requests are sorted by ActionController actions otherwise requests are grouped by url. "+
11
12
  "By default total request times are used for comparison but database time or render time can be used by specifying the correct flag. "+
@@ -22,8 +23,10 @@ module RawkLog
22
23
  " -w <count> Display the top <count> worst requests.\n\n"+
23
24
  " -x <date> Date (inclusive) to start parsing in 'yyyy-mm-dd' format.\n\n"+
24
25
  " -y <date> Date (inclusive) to stop parsing in 'yyyy-mm-dd' format.\n\n"+
25
- "To include process ids in your log file, add this to application's Gemfile:\n\n"+
26
+ "To install the rawk_log command, add this to application's Gemfile and run bundle:\n\n"+
26
27
  " gem 'rawk_log'\n\n"+
28
+ "To enable reporting by controler#action add the following to the end of config/environment.rb:\n\n"+
29
+ " require 'rawk_log/patch_logger'\n\n"+
27
30
  "This software is Beerware, if you like it, buy yourself a beer or something nicer ;)\n"+
28
31
  "\n"+
29
32
  "Example usage:\n"+
@@ -32,7 +35,6 @@ module RawkLog
32
35
  def initialize(args)
33
36
  @start_time = Time.now
34
37
  build_arg_hash(args)
35
- @new_log_format = nil
36
38
  end
37
39
 
38
40
  def run
@@ -93,8 +95,20 @@ module RawkLog
93
95
  @worst_requests = []
94
96
  last_actions = Hash.new
95
97
  last_date = Date.civil
98
+ line_no = 1
96
99
  while @input.gets
97
- if $_.index("Processing ")==0
100
+ line_no += 1
101
+ if $_.index("Processing by ")==0
102
+ action = $_.split[2]
103
+ pid = $_[/\(pid\:\d+\)/]
104
+ last_actions[pid]=action if pid
105
+ elsif $_.index("Started ")==0
106
+ date_string = $_[/(?:19|20)[0-9]{2}-(?:0[1-9]|1[012])-(?:0[1-9]|[12][0-9]|3[01])/]
107
+ date = date_string ? Date.parse(date_string) : last_date
108
+ last_date = date
109
+ datetime = $_[/(?:19|20)[0-9]{2}-(?:0[1-9]|1[012])-(?:0[1-9]|[12][0-9]|3[01]) (?:[0-1][0-9]|2[0-3]):(?:[0-5][0-9]|60):(?:[0-5][0-9]|60)/].to_s
110
+ next
111
+ elsif $_.index("Processing ")==0
98
112
  action = $_.split[1]
99
113
  pid = $_[/\(pid\:\d+\)/]
100
114
  date_string = $_[/(?:19|20)[0-9]{2}-(?:0[1-9]|1[012])-(?:0[1-9]|[12][0-9]|3[01])/]
@@ -104,7 +118,7 @@ module RawkLog
104
118
  last_actions[pid]=action if pid
105
119
  next
106
120
  end
107
- next unless $_.index("Completed in")==0
121
+ next unless $_.index("Completed ")==0 and $_ =~ /^Completed( \d+ \w+)? in/
108
122
  pid = key = nil
109
123
  #get the pid unless we are forcing url tracking
110
124
  pid = $_[/\(pid\:\d+\)/] if !@force_url_use
@@ -113,34 +127,22 @@ module RawkLog
113
127
 
114
128
  # Old: Completed in 0.45141 (2 reqs/sec) | Rendering: 0.25965 (57%) | DB: 0.06300 (13%) | 200 OK [http://localhost/jury/proposal/312]
115
129
  # New: Completed in 100ms (View: 40, DB: 4)
116
- if @new_log_format.nil?
117
- @new_log_format = ! ($_ =~ /Completed in \d+ms/)
118
- end
119
130
 
120
- if @new_log_format
121
- if @db_time
122
- time_string = $_[/DB: \d+\.\d+/]
123
- elsif @render_time
124
- time_string = $_[/(View|Rendering): \d+\.\d+/]
125
- else
126
- time_string = $_[/Completed in \d+\.\d+/]
127
- end
128
- time_string = time_string[/\d+\.\d+/] if time_string
129
- time = time_string.to_f if time_string
131
+ if @db_time
132
+ time_string = $_[/DB: \d+(\.\d+)?[ms]*/]
133
+ elsif @render_time
134
+ time_string = $_[/(View|Rendering): \d+(\.\d+)?[ms]*/]
130
135
  else
131
- if @db_time
132
- time_string = $_[/DB: \d+/]
133
- elsif @render_time
134
- time_string = $_[/View: \d+/]
135
- else
136
- time_string = $_[/Completed in \d+ms/]
137
- end
138
- time_string = time_string[/\d+/] if time_string
139
- time = time_string.to_i if time_string
136
+ time_string = $_[/Completed( \d+ \w+)? in \d+(\.\d+)?[ms]*/]
137
+ time_string = time_string[/ in .*/]
138
+ end
139
+ time_in_ms = time_string && (time_string =~ /ms/ || time_string !~ /\.\d/)
140
+ time_string = time_string[/\d+(\.\d+)?/] if time_string
141
+ if time_string
142
+ time = time_string.to_f
143
+ time /= 1000.0 if time_in_ms
140
144
  end
141
145
 
142
-
143
-
144
146
  #if pids are not specified then we use the url for hashing
145
147
  #the below regexp turns "[http://spongecell.com/calendar/view/bob]" to "/calendar/view"
146
148
  unless key
@@ -166,7 +168,12 @@ module RawkLog
166
168
  end
167
169
  end
168
170
 
169
- if key and (@from.nil? or @from <= date) and (@to.nil? or @to >= date) # date criteria here
171
+ unless key
172
+ key = "Unknown"
173
+ puts "Found Completed without url #{pid ? '' : 'or pid '}at line #{line_no}"
174
+ end
175
+
176
+ if (@from.nil? or @from <= date) and (@to.nil? or @to >= date) # date criteria here
170
177
  @stat_hash.add(key,time)
171
178
  @total_stat.add(time)
172
179
  if @worst_requests.length<@worst_request_length || @worst_requests[@worst_request_length-1][0]<time
@@ -177,6 +184,7 @@ module RawkLog
177
184
  end
178
185
  end
179
186
  end
187
+
180
188
  def print_stats
181
189
  title = "Log Analysis of #{@db_time ? 'DB' : @render_time ? 'render' : 'total'} request times#{@from ? %Q( from #{@from.to_s}) : ""}#{@to ? %Q( through #{@to.to_s}) : ""}"
182
190
  puts title
@@ -1,7 +1,48 @@
1
+ if defined?(Logger)
1
2
 
2
- class Logger
3
- def format_message(severity, timestamp, progname, msg)
4
- "#{msg} (pid:#{$$})\n"
3
+ class Logger
4
+ def format_message(severity, timestamp, progname, msg)
5
+ if msg !~ /^\n*$/ && msg !~ /\(pid\:/
6
+ "#{msg} (pid:#{$$})\n"
7
+ else
8
+ msg
9
+ end
10
+ end
5
11
  end
12
+
13
+ module RawkLog
14
+ PATCHED_LOGGER = true
15
+ end
16
+
6
17
  end
7
18
 
19
+ if defined?(ActiveSupport::BufferedLogger)
20
+
21
+ module ActiveSupport
22
+
23
+ class BufferedLogger
24
+
25
+ def add_with_pid(severity, message = nil, progname = nil, &block)
26
+ add_without_pid(severity) do
27
+ message = (message || (block && block.call) || progname).to_s
28
+ # If a newline is necessary then create a new message ending with a newline.
29
+ # Ensures that the original message is not mutated.
30
+ message = "#{message}\n" unless message[-1] == ?\n
31
+ if message !~ /^\n*$/ && message !~ /\(pid\:/
32
+ message.gsub(/\n/," (pid:#{$$})\n")
33
+ else
34
+ message
35
+ end
36
+ end
37
+ end
38
+
39
+ alias_method_chain :add, :pid
40
+
41
+ end
42
+ end
43
+
44
+ module RawkLog
45
+ PATCHED_BUFFERED_LOGGER = true
46
+ end
47
+
48
+ end
data/lib/rawk_log/stat.rb CHANGED
@@ -17,7 +17,6 @@ module RawkLog
17
17
  end
18
18
 
19
19
  def add(value)
20
- @new_log_format = !value.is_a?(Float)
21
20
  value=1.0*value
22
21
  @count+=1
23
22
  @min = value unless @min
@@ -73,12 +72,7 @@ module RawkLog
73
72
 
74
73
  def to_s(label_size = DEFAULT_LABEL_SIZE)
75
74
  if count > 0
76
- if @new_log_format
77
- sprintf("%*s %6d %9.2f %7d %7d %7d %7d %7d",-label_size, key,count,(sum.to_f/1000),max,median,average,min,standard_deviation)
78
- else
79
- sprintf("%*s %6d %9.2f %7d %7d %7d %7d %7d",-label_size, key,count,sum,max*1000.0,median*1000.0,average*1000.0,min*1000.0,standard_deviation*1000.0)
80
- #sprintf("%*s %6d %9.2f %7.2f %7.2f %7.2f %7.2f %7.2f",-label_size,key,count,sum,max,median,average,min,standard_deviation)
81
- end
75
+ sprintf("%*s %6d %9.2f %7d %7d %7d %7d %7d",-label_size, key,count,sum,max*1000.0,median*1000.0,average*1000.0,min*1000.0,standard_deviation*1000.0)
82
76
  else
83
77
  sprintf("%*s %6d",-label_size,key,0)
84
78
  end
@@ -1,3 +1,3 @@
1
1
  module RawkLog
2
- VERSION = "2.3.0"
2
+ VERSION = "2.4.0"
3
3
  end
data/lib/rawk_log.rb CHANGED
@@ -1,15 +1,11 @@
1
1
  require "rawk_log/version"
2
2
 
3
- # Don't load automatically
3
+ # Don't load command automatically as it is only required by bin/rawk_log
4
4
  #require "rawk_log/command"
5
5
 
6
- if defined?(ActiveSupport::BufferedLogger)
7
- require "rawk_log/patch_logger"
8
- end
9
- if defined?(ActiveSupport::BufferedLogger)
10
- require "rawk_log/patch_activesupport_bufferedlogger"
11
- end
6
+ # Don't load patch_logger automatically as some may not want their log patched
7
+ #require "rawk_log/patch_logger"
12
8
 
13
9
  module RawkLog
14
- # Everything loaded in requires above
10
+
15
11
  end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rawk_log'
data/rawk_log.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = RawkLog::VERSION
9
9
  spec.authors = ["Chris Hobbs", "Ian Heggie"]
10
10
  spec.email = ["chris.hobbs@unknown.due.to.spam", "ian@heggie.biz"]
11
- spec.description = %q{RawkLog - RAWK - Rail's Analyzer With Klass updated and packaged a Gem}
11
+ spec.description = %q{RawkLog - RAWK - Rail's Analyzer With Klass for log files}
12
12
  spec.summary = %q{This tool gives statistics for Ruby on Rails log files. The times for each request are grouped and totals are displayed. If process ids are present in the log files then requests are sorted by ActionController actions otherwise requests are grouped by url. By default total request times are used for comparison but database time or render time can be used by specifying the correct flag. The log file is read from standard input unless the -f flag is specified.}
13
13
  spec.homepage = "https://github.com/ianheggie/rawk_log"
14
14
  spec.license = "Beerware"
File without changes
@@ -8,7 +8,7 @@ Completed in 25ms (View: 22, DB: 20) | 200 OK [http://0.0.0.0/items]
8
8
  Processing ItemsController#index (for 127.0.0.1 at 2009-01-08 03:06:39) [GET]
9
9
  Rendering template within layouts/items
10
10
  Rendering items/index
11
- Completed in 15ms (View: 12, DB: 10) | 200 OK [http://0.0.0.0/items]
11
+ Completed in 16 (View: 12, DB: 10) | 200 OK [http://0.0.0.0/items]
12
12
 
13
13
  Processing ItemsController#index (for 127.0.0.1 at 2009-01-08 03:06:39) [GET]
14
14
  Rendering template within layouts/items
@@ -0,0 +1,79 @@
1
+ # From http://railscasts.com/episodes/56-the-logger-revised?view=asciicast
2
+
3
+ Started GET "/" for 127.0.0.1 at 2012-04-23 20:59:50 +0100
4
+ Processing by ArticlesController#index as HTML
5
+ Article Load (0.1ms) SELECT "articles".* FROM "articles"
6
+ Articles Count: 3
7
+ Rendered articles/index.html.erb within layouts/application (2.8ms)
8
+ Completed 200 OK in 18ms (Views: 8.4ms | ActiveRecord: 0.7ms)
9
+ [2012-04-23 20:59:50] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
10
+
11
+ # sample from initial app
12
+
13
+ Started GET "/rails/info/properties" for 127.0.0.1 at 2013-12-24 02:46:48 +1100 (pid:13028)
14
+ Processing by Rails::InfoController#properties as HTML (pid:13028)
15
+ Rendered inline template (0.5ms) (pid:13028)
16
+ Completed 200 OK in 1.7ms (Views: 1.1ms | ActiveRecord: 0.0ms) (pid:13028)
17
+ [2013-12-24 02:46:48] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
18
+
19
+
20
+ Started GET "/rails/info/properties" for 127.0.0.1 at 2013-12-24 02:46:51 +1100 (pid:13028)
21
+ Processing by Rails::InfoController#properties as HTML (pid:13028)
22
+ Rendered inline template (0.5ms) (pid:13028)
23
+ Completed 200 OK in 1.8ms (Views: 1.2ms | ActiveRecord: 0.0ms) (pid:13028)
24
+ [2013-12-24 02:46:51] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
25
+
26
+
27
+ Started GET "/rails/info/properties" for 127.0.0.1 at 2013-12-24 02:46:54 +1100 (pid:13028)
28
+ Processing by Rails::InfoController#properties as HTML (pid:13028)
29
+ Rendered inline template (0.5ms) (pid:13028)
30
+ Completed 200 OK in 1.4ms (Views: 1.0ms | ActiveRecord: 0.0ms) (pid:13028)
31
+ [2013-12-24 02:46:54] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
32
+
33
+
34
+ Started GET "/rails/info/properties" for 127.0.0.1 at 2013-12-24 02:46:48 +1100 (pid:13028)
35
+ Processing by Rails::InfoController#properties as HTML (pid:13028)
36
+ Rendered inline template (0.5ms) (pid:13028)
37
+ Completed 200 OK in 1.7ms (Views: 1.1ms | ActiveRecord: 0.0ms) (pid:13028)
38
+ [2013-12-24 02:46:48] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
39
+
40
+
41
+ Started GET "/rails/info/properties" for 127.0.0.1 at 2013-12-24 02:46:51 +1100 (pid:13028)
42
+ Processing by Rails::InfoController#properties as HTML (pid:13028)
43
+ Rendered inline template (0.5ms) (pid:13028)
44
+ Completed 200 OK in 1.8ms (Views: 1.2ms | ActiveRecord: 0.0ms) (pid:13028)
45
+ [2013-12-24 02:46:51] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
46
+
47
+
48
+ Started GET "/rails/info/properties" for 127.0.0.1 at 2013-12-24 02:46:54 +1100 (pid:13028)
49
+ Processing by Rails::InfoController#properties as HTML (pid:13028)
50
+ Rendered inline template (0.5ms) (pid:13028)
51
+ Completed 200 OK in 1.4ms (Views: 1.0ms | ActiveRecord: 0.0ms) (pid:13028)
52
+ [2013-12-24 02:46:54] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
53
+
54
+ Started GET "/rails/info/properties" for 127.0.0.1 at 2013-12-24 02:46:48 +1100 (pid:13028)
55
+ Processing by Rails::InfoController#properties as HTML (pid:13028)
56
+ Rendered inline template (0.5ms) (pid:13028)
57
+ Completed 200 OK in 1.7ms (Views: 1.1ms | ActiveRecord: 0.0ms) (pid:13028)
58
+ [2013-12-24 02:46:48] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
59
+
60
+
61
+ Started GET "/rails/info/properties" for 127.0.0.1 at 2013-12-24 02:46:51 +1100 (pid:13028)
62
+ Processing by Rails::InfoController#properties as HTML (pid:13028)
63
+ Rendered inline template (0.5ms) (pid:13028)
64
+ Completed 200 OK in 1.8ms (Views: 1.2ms | ActiveRecord: 0.0ms) (pid:13028)
65
+ [2013-12-24 02:46:51] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
66
+
67
+
68
+ Started GET "/rails/info/properties" for 127.0.0.1 at 2013-12-24 02:46:54 +1100 (pid:13028)
69
+ Processing by Rails::InfoController#properties as HTML (pid:13028)
70
+ Rendered inline template (0.5ms) (pid:13028)
71
+ Completed 200 OK in 1.4ms (Views: 1.0ms | ActiveRecord: 0.0ms) (pid:13028)
72
+ [2013-12-24 02:46:54] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
73
+
74
+
75
+ Started GET "/rails/info/properties" for 127.0.0.1 at 2013-12-24 02:46:48 +1100 (pid:13028)
76
+ Processing by Rails::InfoController#properties as HTML (pid:13028)
77
+ Rendered inline template (0.5ms) (pid:13028)
78
+ Completed 200 OK in 1.7ms (Views: 1.1ms | ActiveRecord: 0.0ms) (pid:13028)
79
+ [2013-12-24 02:46:48] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
@@ -1,10 +1,13 @@
1
- # From http://railscasts.com/episodes/56-the-logger-revised?view=asciicast
1
+ Some unknown log format
2
2
 
3
- Started GET "/" for 127.0.0.1 at 2012-04-23 20:59:50 +0100
4
- Processing by ArticlesController#index as HTML
5
- Article Load (0.1ms) SELECT "articles".* FROM "articles"
6
- Articles Count: 3
7
- Rendered articles/index.html.erb within layouts/application (2.8ms)
8
- Completed 200 OK in 18ms (Views: 8.4ms | ActiveRecord: 0.7ms)
9
- [2012-04-23 20:59:50] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
10
3
 
4
+
5
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis auctor dolor laoreet sapien malesuada porttitor. Donec quis eros convallis, dapibus urna vitae, aliquam ipsum. Etiam egestas porttitor magna non hendrerit. Proin condimentum purus a felis viverra ullamcorper. Nunc ac cursus odio, ut sollicitudin enim. Nam feugiat porta libero, non viverra est. In id felis venenatis enim sodales tincidunt ultrices ut eros. Donec sed diam sed diam consequat luctus. Donec diam eros, euismod sed nisi id, semper viverra lacus. Nam elementum ligula ut pretium commodo. Phasellus ullamcorper augue ligula, quis pulvinar tortor porta vel. In iaculis turpis at ligula pellentesque, vitae cursus felis viverra. Morbi vehicula dolor et augue placerat interdum. Maecenas pulvinar consequat cursus. Donec accumsan, massa venenatis tristique dignissim, ante diam tempor lacus, eu imperdiet neque orci quis lacus. Curabitur lectus mi, pellentesque sit amet pulvinar aliquet, tincidunt quis orci.
6
+
7
+ Nullam pulvinar velit placerat enim ultricies posuere. Nullam pulvinar tortor lacus, ut sodales leo porttitor quis. Etiam quis dapibus risus, nec auctor ante. Vivamus rhoncus turpis eu turpis convallis molestie. Suspendisse blandit tellus fermentum laoreet consequat. Aenean volutpat tortor in risus ultrices, nec placerat velit sagittis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus eros libero, congue at tortor non, placerat aliquet urna. Praesent et dui id ligula ultrices rutrum at at risus. Proin vehicula, massa nec facilisis vehicula, dolor nisi pellentesque augue, nec hendrerit sapien est nec risus. Proin tincidunt, mauris in dapibus fermentum, purus quam faucibus felis, ac ornare elit sapien vel libero.
8
+
9
+ Pellentesque rhoncus vel tellus a sagittis. Aliquam porttitor, nisl sed tempus semper, nulla tortor scelerisque enim, sed placerat urna libero at eros. Etiam ut leo tristique, tristique lectus ac, adipiscing ipsum. Praesent pharetra ante ut est luctus, vel gravida urna bibendum. Proin eu justo arcu. Proin malesuada tellus ipsum, vitae porttitor urna tincidunt tempor. Nam rutrum ante augue.
10
+
11
+ Fusce viverra elit id placerat congue. Pellentesque dapibus id leo eu egestas. Proin rutrum laoreet vehicula. Phasellus metus eros, feugiat eu massa in, congue varius felis. Proin justo purus, venenatis eget urna eget, condimentum convallis dui. Duis sed odio sit amet ipsum venenatis convallis vel eget lorem. Fusce eu tellus sem.
12
+
13
+ Nulla euismod lorem eget placerat placerat. Morbi ut nisl eu nunc sagittis rutrum id at tellus. Praesent blandit elit vitae varius volutpat. Duis convallis nec velit et tristique. In hac habitasse platea dictumst. Mauris consequat, lacus in ullamcorper vulputate, libero velit rutrum diam, sed congue lacus dui at nisi. Curabitur vitae varius leo. Aliquam nisl arcu, dapibus et consectetur non, viverra non erat. Mauris lacinia hendrerit nisi a lobortis. Cras sagittis orci eros, a commodo nibh dapibus et. Duis ut neque vitae lacus pulvinar posuere eget in massa. Fusce tellus nulla, eleifend at tempus volutpat, tincidunt at mauris. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean eu massa et tortor vehicula lacinia a a mi. Aliquam feugiat tellus vitae elit aliquet, nec sollicitudin dolor viverra.
@@ -1,11 +1,11 @@
1
1
  require 'test/unit'
2
2
 
3
- class MixedRails40Test < Test::Unit::TestCase
3
+ class MixedTest < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  bin = File.join(File.dirname(__FILE__), '..', 'bin')
7
7
  examples = File.join(File.dirname(__FILE__), 'examples')
8
- @output = `ruby #{bin}/rawk_log -f #{examples}/mixed_rails40.log`
8
+ @output = `ruby #{bin}/rawk_log -f #{examples}/mixed.log`
9
9
  @exit_status = $?.to_i
10
10
  end
11
11
 
@@ -0,0 +1,51 @@
1
+ require 'test/unit'
2
+
3
+ class Rails32Test < Test::Unit::TestCase
4
+
5
+ def setup
6
+ bin = File.join(File.dirname(__FILE__), '..', 'bin')
7
+ examples = File.join(File.dirname(__FILE__), 'examples')
8
+ @output = `ruby #{bin}/rawk_log -f #{examples}/rails32.log`
9
+ @exit_status = $?.to_i
10
+ end
11
+
12
+ def test_methods_reported
13
+ assert_match(/Rails::InfoController#properties/, @output)
14
+ end
15
+
16
+ def test_results_without_pid_not_matched_to_url
17
+ assert_no_match(/^\/ /, @output)
18
+ end
19
+
20
+ def test_results_without_pid_not_matched_to_method
21
+ assert_no_match(/ArticlesController#index/, @output)
22
+ end
23
+
24
+ def test_results_without_pid_reported_as_unknown
25
+ assert_match(/^Unknown/, @output)
26
+ assert_match(/^Unknown\s+1\s/, @output)
27
+ assert_match(/^Unknown\s+1\s+0.02/, @output)
28
+ end
29
+
30
+ def test_has_top_lists
31
+ assert_match(/^Top /, @output)
32
+ end
33
+
34
+ def test_outputs_header
35
+ assert_match(/^Request +Count +Sum\(secs\) +Max +Median +Avg +Min +Std$/, @output)
36
+ end
37
+
38
+ def test_finds_entries
39
+ assert_match(/^Rails::InfoController#properties/, @output)
40
+ assert_match(/^Rails::InfoController#properties\s+10\s/, @output)
41
+ end
42
+
43
+ def test_sums_entries
44
+ assert_match(/^Rails::InfoController#properties\s+10\s+0.02/, @output)
45
+ end
46
+
47
+ def test_exit_status
48
+ assert_equal(0, @exit_status)
49
+ end
50
+
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rawk_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-12-22 00:00:00.000000000 Z
13
+ date: 2013-12-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -44,7 +44,7 @@ dependencies:
44
44
  - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
- description: RawkLog - RAWK - Rail's Analyzer With Klass updated and packaged a Gem
47
+ description: RawkLog - RAWK - Rail's Analyzer With Klass for log files
48
48
  email:
49
49
  - chris.hobbs@unknown.due.to.spam
50
50
  - ian@heggie.biz
@@ -62,20 +62,22 @@ files:
62
62
  - bin/rawk_log
63
63
  - lib/rawk_log.rb
64
64
  - lib/rawk_log/command.rb
65
- - lib/rawk_log/patch_activesupport_bufferedlogger.rb
66
65
  - lib/rawk_log/patch_logger.rb
67
66
  - lib/rawk_log/stat.rb
68
67
  - lib/rawk_log/stat_hash.rb
69
68
  - lib/rawk_log/version.rb
69
+ - rails/init.rb
70
70
  - rawk_log.gemspec
71
71
  - test/empty_test.rb
72
72
  - test/examples/empty.log
73
- - test/examples/mixed_rails40.log
73
+ - test/examples/mixed.log
74
74
  - test/examples/rails23.log
75
+ - test/examples/rails32.log
75
76
  - test/examples/rails40.log
76
77
  - test/examples/unknown.log
77
- - test/mixed_rails40_test.rb
78
+ - test/mixed_test.rb
78
79
  - test/rails23_test.rb
80
+ - test/rails32_test.rb
79
81
  - test/rails40_test.rb
80
82
  - test/self_test.rb
81
83
  - test/unknown_test.rb
@@ -112,12 +114,14 @@ summary: This tool gives statistics for Ruby on Rails log files. The times for e
112
114
  test_files:
113
115
  - test/empty_test.rb
114
116
  - test/examples/empty.log
115
- - test/examples/mixed_rails40.log
117
+ - test/examples/mixed.log
116
118
  - test/examples/rails23.log
119
+ - test/examples/rails32.log
117
120
  - test/examples/rails40.log
118
121
  - test/examples/unknown.log
119
- - test/mixed_rails40_test.rb
122
+ - test/mixed_test.rb
120
123
  - test/rails23_test.rb
124
+ - test/rails32_test.rb
121
125
  - test/rails40_test.rb
122
126
  - test/self_test.rb
123
127
  - test/unknown_test.rb
@@ -1,19 +0,0 @@
1
-
2
- module ActiveSupport
3
-
4
- # Format the buffered logger with timestamp/severity info.
5
- class BufferedLogger
6
- def add(severity, message = nil, progname = nil, &block)
7
- return if @level > severity
8
- message = (message || (block && block.call) || progname).to_s
9
- # If a newline is necessary then create a new message ending with a newline.
10
- # Ensures that the original message is not mutated.
11
- message = "#{message}\n" unless message[-1] == ?\n
12
- message = message.gsub(/\n/," (pid:#{$$})\n")
13
- buffer << message
14
- auto_flush
15
- message
16
- end
17
- end
18
- end
19
-