ngmoco-request-log-analyzer 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/.gitignore +10 -0
  2. data/DESIGN.rdoc +41 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +39 -0
  5. data/Rakefile +8 -0
  6. data/bin/request-log-analyzer +114 -0
  7. data/lib/cli/command_line_arguments.rb +301 -0
  8. data/lib/cli/database_console.rb +26 -0
  9. data/lib/cli/database_console_init.rb +43 -0
  10. data/lib/cli/progressbar.rb +213 -0
  11. data/lib/cli/tools.rb +46 -0
  12. data/lib/request_log_analyzer.rb +44 -0
  13. data/lib/request_log_analyzer/aggregator.rb +49 -0
  14. data/lib/request_log_analyzer/aggregator/database_inserter.rb +83 -0
  15. data/lib/request_log_analyzer/aggregator/echo.rb +29 -0
  16. data/lib/request_log_analyzer/aggregator/summarizer.rb +175 -0
  17. data/lib/request_log_analyzer/controller.rb +332 -0
  18. data/lib/request_log_analyzer/database.rb +102 -0
  19. data/lib/request_log_analyzer/database/base.rb +115 -0
  20. data/lib/request_log_analyzer/database/connection.rb +38 -0
  21. data/lib/request_log_analyzer/database/request.rb +22 -0
  22. data/lib/request_log_analyzer/database/source.rb +13 -0
  23. data/lib/request_log_analyzer/database/warning.rb +14 -0
  24. data/lib/request_log_analyzer/file_format.rb +160 -0
  25. data/lib/request_log_analyzer/file_format/amazon_s3.rb +71 -0
  26. data/lib/request_log_analyzer/file_format/apache.rb +141 -0
  27. data/lib/request_log_analyzer/file_format/merb.rb +67 -0
  28. data/lib/request_log_analyzer/file_format/rack.rb +11 -0
  29. data/lib/request_log_analyzer/file_format/rails.rb +176 -0
  30. data/lib/request_log_analyzer/file_format/rails_development.rb +12 -0
  31. data/lib/request_log_analyzer/filter.rb +30 -0
  32. data/lib/request_log_analyzer/filter/anonymize.rb +39 -0
  33. data/lib/request_log_analyzer/filter/field.rb +42 -0
  34. data/lib/request_log_analyzer/filter/timespan.rb +45 -0
  35. data/lib/request_log_analyzer/line_definition.rb +111 -0
  36. data/lib/request_log_analyzer/log_processor.rb +99 -0
  37. data/lib/request_log_analyzer/mailer.rb +62 -0
  38. data/lib/request_log_analyzer/output.rb +113 -0
  39. data/lib/request_log_analyzer/output/fixed_width.rb +220 -0
  40. data/lib/request_log_analyzer/output/html.rb +184 -0
  41. data/lib/request_log_analyzer/request.rb +175 -0
  42. data/lib/request_log_analyzer/source.rb +72 -0
  43. data/lib/request_log_analyzer/source/database_loader.rb +87 -0
  44. data/lib/request_log_analyzer/source/log_parser.rb +274 -0
  45. data/lib/request_log_analyzer/tracker.rb +206 -0
  46. data/lib/request_log_analyzer/tracker/duration.rb +104 -0
  47. data/lib/request_log_analyzer/tracker/frequency.rb +95 -0
  48. data/lib/request_log_analyzer/tracker/hourly_spread.rb +107 -0
  49. data/lib/request_log_analyzer/tracker/timespan.rb +81 -0
  50. data/lib/request_log_analyzer/tracker/traffic.rb +106 -0
  51. data/request-log-analyzer.gemspec +40 -0
  52. data/spec/database.yml +23 -0
  53. data/spec/fixtures/apache_combined.log +5 -0
  54. data/spec/fixtures/apache_common.log +10 -0
  55. data/spec/fixtures/decompression.log +12 -0
  56. data/spec/fixtures/decompression.log.bz2 +0 -0
  57. data/spec/fixtures/decompression.log.gz +0 -0
  58. data/spec/fixtures/decompression.log.zip +0 -0
  59. data/spec/fixtures/decompression.tar.gz +0 -0
  60. data/spec/fixtures/decompression.tgz +0 -0
  61. data/spec/fixtures/header_and_footer.log +6 -0
  62. data/spec/fixtures/merb.log +84 -0
  63. data/spec/fixtures/merb_prefixed.log +9 -0
  64. data/spec/fixtures/multiple_files_1.log +5 -0
  65. data/spec/fixtures/multiple_files_2.log +2 -0
  66. data/spec/fixtures/rails.db +0 -0
  67. data/spec/fixtures/rails_1x.log +59 -0
  68. data/spec/fixtures/rails_22.log +12 -0
  69. data/spec/fixtures/rails_22_cached.log +10 -0
  70. data/spec/fixtures/rails_unordered.log +24 -0
  71. data/spec/fixtures/syslog_1x.log +5 -0
  72. data/spec/fixtures/test_file_format.log +13 -0
  73. data/spec/fixtures/test_language_combined.log +14 -0
  74. data/spec/fixtures/test_order.log +16 -0
  75. data/spec/integration/command_line_usage_spec.rb +84 -0
  76. data/spec/integration/munin_plugins_rails_spec.rb +58 -0
  77. data/spec/integration/scout_spec.rb +151 -0
  78. data/spec/lib/helpers.rb +52 -0
  79. data/spec/lib/macros.rb +18 -0
  80. data/spec/lib/matchers.rb +77 -0
  81. data/spec/lib/mocks.rb +76 -0
  82. data/spec/lib/testing_format.rb +46 -0
  83. data/spec/spec_helper.rb +24 -0
  84. data/spec/unit/aggregator/database_inserter_spec.rb +93 -0
  85. data/spec/unit/aggregator/summarizer_spec.rb +26 -0
  86. data/spec/unit/controller/controller_spec.rb +41 -0
  87. data/spec/unit/controller/log_processor_spec.rb +18 -0
  88. data/spec/unit/database/base_class_spec.rb +183 -0
  89. data/spec/unit/database/connection_spec.rb +34 -0
  90. data/spec/unit/database/database_spec.rb +133 -0
  91. data/spec/unit/file_format/amazon_s3_format_spec.rb +49 -0
  92. data/spec/unit/file_format/apache_format_spec.rb +203 -0
  93. data/spec/unit/file_format/file_format_api_spec.rb +69 -0
  94. data/spec/unit/file_format/line_definition_spec.rb +75 -0
  95. data/spec/unit/file_format/merb_format_spec.rb +52 -0
  96. data/spec/unit/file_format/rails_format_spec.rb +164 -0
  97. data/spec/unit/filter/anonymize_filter_spec.rb +21 -0
  98. data/spec/unit/filter/field_filter_spec.rb +66 -0
  99. data/spec/unit/filter/filter_spec.rb +17 -0
  100. data/spec/unit/filter/timespan_filter_spec.rb +58 -0
  101. data/spec/unit/mailer_spec.rb +30 -0
  102. data/spec/unit/request_spec.rb +111 -0
  103. data/spec/unit/source/log_parser_spec.rb +119 -0
  104. data/spec/unit/tracker/duration_tracker_spec.rb +130 -0
  105. data/spec/unit/tracker/frequency_tracker_spec.rb +88 -0
  106. data/spec/unit/tracker/hourly_spread_spec.rb +79 -0
  107. data/spec/unit/tracker/timespan_tracker_spec.rb +73 -0
  108. data/spec/unit/tracker/tracker_api_spec.rb +124 -0
  109. data/spec/unit/tracker/traffic_tracker_spec.rb +107 -0
  110. data/tasks/github-gem.rake +323 -0
  111. data/tasks/request_log_analyzer.rake +26 -0
  112. metadata +220 -0
@@ -0,0 +1,12 @@
1
+ Processing PageController#demo (for 127.0.0.1 at 2008-12-10 16:28:09) [GET]
2
+ Parameters: {"action"=>"demo", "controller"=>"page"}
3
+ Logging in from session data...
4
+ Logged in as test@example.com
5
+ Using locale: en-US, http-accept: ["en-US"], session: , det browser: en-US, det domain:
6
+ Rendering template within layouts/demo
7
+ Rendering page/demo
8
+ Rendered shared/_analytics (0.2ms)
9
+ Rendered layouts/_actions (0.6ms)
10
+ Rendered layouts/_menu (2.2ms)
11
+ Rendered layouts/_tabbar (0.5ms)
12
+ Completed in 614ms (View: 120, DB: 31) | 200 OK [http://www.example.com/demo]
@@ -0,0 +1,10 @@
1
+ Processing CachedController#cached (for 1.1.1.1 at 2008-12-24 07:36:53) [GET]
2
+ Parameters: {"action"=>"cached", "controller"=>"cached"}
3
+ Logging in from session data...
4
+ Logging in using cookie...
5
+ Using locale: zh-Hans, http-accept: ["zh-CN", "zh-HK", "zh-TW", "en-US"], session: , det browser: zh-Hans, det domain: , user pref locale:
6
+ Referer: http://www.example.com/referer
7
+ Cached fragment hit: views/zh-Hans-www-cached-cached-all-CN--- (0.0ms)
8
+ Filter chain halted as [#<ActionController::Caching::Actions::ActionCacheFilter:0x2a999ad620 @check=nil, @options={:store_options=>{}, :layout=>nil, :cache_path=>#<Proc:0x0000002a999b8890@/app/controllers/cached_controller.rb:8>}>] rendered_or_redirected.
9
+ Filter chain halted as [#<ActionController::Filters::AroundFilter:0x2a999ad120 @identifier=nil, @kind=:filter, @options={:only=>#<Set: {"cached"}>, :if=>:not_logged_in?, :unless=>nil}, @method=#<ActionController::Caching::Actions::ActionCacheFilter:0x2a999ad620 @check=nil, @options={:store_options=>{}, :layout=>nil, :cache_path=>#<Proc:0x0000002a999b8890@/app/controllers/cached_controller.rb:8>}>>] did_not_yield.
10
+ Completed in 3ms (View: 0, DB: 0) | 200 OK [http://www.example.com/cached/cached/]
@@ -0,0 +1,24 @@
1
+ Processing AccountController#dashboard (for 1.1.1.1 at 2008-12-24 07:36:49) [GET]
2
+ Parameters: {"action"=>"dashboard", "controller"=>"account", "first_use"=>"true"}
3
+ Logging in from session data...
4
+
5
+
6
+ Processing ProjectsController#new (for 1.1.1.1 at 2008-12-24 07:36:49) [GET]
7
+ Parameters: {"action"=>"new", "controller"=>"projects"}
8
+ Rendering template within layouts/default
9
+ Rendering account/dashboard
10
+ Logging in from session data...
11
+ Logging in using cookie...
12
+ Using locale: en-US, http-accept: [], session: , det browser: , det domain: , user pref locale:
13
+ Rendered shared/_maintenance (0.6ms)
14
+ Rendering template within layouts/templates/general_default/index.html.erb
15
+ Rendered projects/_recent_designs (4.3ms)
16
+ Rendered projects/_project (13.6ms)
17
+ Rendered projects/_projects (18.7ms)
18
+ Rendered layouts/_menu (1.4ms)
19
+ Completed in 36ms (View: 30, DB: 3) | 200 OK [http://www.example.com/projects/new]
20
+ Rendered layouts/_actions (0.3ms)
21
+ Rendered layouts/_menu (1.6ms)
22
+ Rendered layouts/_tabbar (1.9ms)
23
+ Rendered layouts/_footer (3.2ms)
24
+ Completed in 50ms (View: 41, DB: 4) | 200 OK [http://www.example.com/dashboard?first_use=true]
@@ -0,0 +1,5 @@
1
+ Jul 13 06:25:58 10.1.1.32 app_p [1957]: Processing EmployeeController#index (for 10.1.1.33 at 2008-07-13 06:25:58) [GET]
2
+ Jul 13 06:25:58 10.1.1.32 app_p [1957]: Session ID: bd1810833653be11c38ad1e5675635bd
3
+ Jul 13 06:25:58 10.1.1.32 app_p [1957]: Parameters: {"format"=>"xml", "action"=>"index}
4
+ Jul 13 06:25:58 10.1.1.32 app_p [1957]: Rendering employees
5
+ Jul 13 06:25:58 10.1.1.32 app_p [1957]: Completed in 0.21665 (4 reqs/sec) | Rendering: 0.00926 (4%) | DB: 0.00000 (0%) | 200 OK [http://example.com/employee.xml]
@@ -0,0 +1,13 @@
1
+ processing request 1
2
+ testing
3
+ testing methods
4
+ testing is cool
5
+ testing fixtures
6
+ testing is amazing
7
+ testing can be cumbersome
8
+ testing
9
+ nonsense
10
+ testing is
11
+
12
+ more nonsense
13
+ finishing request 1
@@ -0,0 +1,14 @@
1
+ initializing
2
+
3
+ processing request 1
4
+
5
+ testing is amazing
6
+ testing is cool
7
+
8
+ finishing request 1
9
+
10
+ asdfad # garbage
11
+ dsaads # garbage
12
+
13
+ processing request 1
14
+ finishing request 1
@@ -0,0 +1,16 @@
1
+ initializing
2
+
3
+ processing request 1
4
+
5
+ testing is amazing
6
+ testing is cool
7
+
8
+ processing request 1
9
+ testing is cool
10
+ finishing request 1
11
+
12
+ asdfad # garbage
13
+ dsaads # garbage
14
+
15
+
16
+ finishing request 1
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe RequestLogAnalyzer, 'running from command line' do
4
+
5
+ before(:each) do
6
+ cleanup_temp_files!
7
+ end
8
+
9
+ after(:each) do
10
+ cleanup_temp_files!
11
+ end
12
+
13
+ it "should find 4 requests in default mode" do
14
+ output = run("#{log_fixture(:rails_1x)}")
15
+ output.any? { |line| /^Parsed requests\:\s*4\s/ =~ line }.should be_true
16
+ end
17
+
18
+ it "should find 2 requests when parsing a compressed file" do
19
+ output = run("#{log_fixture(:decompression, :tgz)}")
20
+ output.any? { |line| /^Parsed requests\:\s*2\s/ =~ line }.should be_true
21
+ end
22
+
23
+
24
+ it "should skip 1 requests with a --select option" do
25
+ output = run("#{log_fixture(:rails_1x)} --select controller PeopleController")
26
+ output.any? { |line| /^Skipped requests\:\s*1\s/ =~ line }.should be_true
27
+ end
28
+
29
+ it "should skip 3 requests with a --reject option" do
30
+ output = run("#{log_fixture(:rails_1x)} --reject controller PeopleController")
31
+ output.any? { |line| /^Skipped requests\:\s*3\s/ =~ line }.should be_true
32
+ end
33
+
34
+ it "should write output to a file with the --file option" do
35
+ run("#{log_fixture(:rails_1x)} --file #{temp_output_file(:report)}")
36
+ File.exist?(temp_output_file(:report)).should be_true
37
+ end
38
+
39
+ it "should write only ASCII characters to a file with the --file option" do
40
+ run("#{log_fixture(:rails_1x)} --file #{temp_output_file(:report)}")
41
+ /^[\x00-\x7F]*$/.match(File.read(temp_output_file(:report))).should_not be_nil
42
+ end
43
+
44
+ it "should write HTML if --output HTML is provided" do
45
+ output = run("#{log_fixture(:rails_1x)} --output HTML")
46
+ output.any? { |line| /<html[^>]*>/ =~ line}.should be_true
47
+ end
48
+
49
+ it "should run with the --database option" do
50
+ run("#{log_fixture(:rails_1x)} --database #{temp_output_file(:database)}")
51
+ File.exist?(temp_output_file(:database)).should be_true
52
+ end
53
+
54
+ it "should use no colors in the report with the --boring option" do
55
+ output = run("#{log_fixture(:rails_1x)} --boring")
56
+ output.any? { |line| /\e/ =~ line }.should be_false
57
+ end
58
+
59
+ it "should use only ASCII characters in the report with the --boring option" do
60
+ output = run("#{log_fixture(:rails_1x)} --boring")
61
+ output.all? { |line| /^[\x00-\x7F]*$/ =~ line }.should be_true
62
+ end
63
+
64
+ it "should parse a Merb file if --format merb is set" do
65
+ output = run("#{log_fixture(:merb)} --format merb")
66
+ output.any? { |line| /Parsed requests\:\s*11/ =~ line }.should be_true
67
+ end
68
+
69
+ it "should parse a Apache access log file if --apache-format is set" do
70
+ output = run("#{log_fixture(:apache_combined)} --apache-format combined")
71
+ output.any? { |line| /Parsed requests\:\s*5/ =~ line }.should be_true
72
+ end
73
+
74
+ it "should dump the results to a YAML file" do
75
+ run("#{log_fixture(:rails_1x)} --dump #{temp_output_file(:yaml)}")
76
+ File.exist?(temp_output_file(:yaml)).should be_true
77
+ YAML::load(File.read(temp_output_file(:yaml))).should have_at_least(1).item
78
+ end
79
+
80
+ it "should parse 4 requests from the standard input" do
81
+ output = run("- < #{log_fixture(:rails_1x)}")
82
+ output.any? { |line| /^Parsed requests\:\s*4\s/ =~ line }.should be_true
83
+ end
84
+ end
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe RequestLogAnalyzer, 'when harvesting like munin-plugins-rails the YAML output' do
4
+
5
+ before(:each) do
6
+ cleanup_temp_files!
7
+ run("#{log_fixture(:rails_1x)} --dump #{temp_output_file(:yaml)}")
8
+ @rla = YAML::load(File.read(temp_output_file(:yaml)))
9
+ end
10
+
11
+ after(:each) do
12
+ cleanup_temp_files!
13
+ end
14
+
15
+ it "should contain database times" do
16
+ @rla["Database time"].each do |item|
17
+ item[1][:min].should_not be_nil
18
+ item[1][:max].should_not be_nil
19
+ item[1][:hits].should_not be_nil
20
+ item[1][:sum].should_not be_nil
21
+ end
22
+ end
23
+
24
+ it "should contain request times" do
25
+ @rla["Request duration"].each do |item|
26
+ item[1][:min].should_not be_nil
27
+ item[1][:max].should_not be_nil
28
+ item[1][:hits].should_not be_nil
29
+ item[1][:sum].should_not be_nil
30
+ end
31
+ end
32
+
33
+ it "should contain failed requests" do
34
+ @rla.keys.should include("Failed requests")
35
+ end
36
+
37
+ it "should contain Process blockers" do
38
+ @rla.keys.should include("Process blockers (> 1 sec duration)")
39
+ end
40
+
41
+ it "should contain HTTP Methods" do
42
+ @rla["HTTP methods"]["GET"].should_not be_nil
43
+ end
44
+
45
+ it "should contain HTTP Methods" do
46
+ @rla["HTTP methods"]["GET"].should_not be_nil
47
+ end
48
+
49
+ it "should contain view rendering times" do
50
+ @rla["View rendering time"].each do |item|
51
+ item[1][:min].should_not be_nil
52
+ item[1][:max].should_not be_nil
53
+ item[1][:hits].should_not be_nil
54
+ item[1][:sum].should_not be_nil
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,151 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ def capture_stdout_and_stderr_with_warnings_on
4
+ $stdout, $stderr, warnings, $VERBOSE =
5
+ StringIO.new, StringIO.new, $VERBOSE, true
6
+ yield
7
+ return $stdout.string, $stderr.string
8
+ ensure
9
+ $stdout, $stderr, $VERBOSE = STDOUT, STDERR, warnings
10
+ end
11
+
12
+ describe RequestLogAnalyzer, 'when using the rla API like the scout plugin' do
13
+
14
+ before(:each) do
15
+ # prepare a place to capture the output
16
+ sio = StringIO.new
17
+
18
+ # place an IO object where I want RequestLogAnalyzer to read from
19
+ open(log_fixture(:rails_1x)) do |log|
20
+ completed_count = 0
21
+ log.each do |line|
22
+ completed_count += 1 if line =~ /\ACompleted\b/
23
+ break if completed_count == 2 # skipping first two requests
24
+ end
25
+
26
+ # trigger the log parse
27
+ @stdout, @stderr = capture_stdout_and_stderr_with_warnings_on do
28
+ RequestLogAnalyzer::Controller.build(
29
+ :output => EmbeddedHTML,
30
+ :file => sio,
31
+ :after => Time.local(2008, 8, 14, 21, 16, 31), # after 3rd req
32
+ :source_files => log
33
+ ).run!
34
+ end
35
+ end
36
+
37
+ # read the resulting output
38
+ @analysis = sio.string
39
+ end
40
+
41
+ it "should generate an analysis" do
42
+ @analysis.should_not be_empty
43
+ end
44
+
45
+ it "should generate customized output using the passed Class" do
46
+ credit = %r{<p>Powered by request-log-analyzer v\d+(?:\.\d+)+</p>\z}
47
+ @analysis.should match(credit)
48
+ end
49
+
50
+ it "should skip requests before :after Time" do
51
+ @analysis.should_not include("PeopleController#show")
52
+ end
53
+
54
+ it "should include requests after IO#pos and :after Time" do
55
+ @analysis.should include("PeopleController#picture")
56
+ end
57
+
58
+ it "should skip requests before IO#pos" do
59
+ @analysis.should_not include("PeopleController#index")
60
+ end
61
+
62
+ it "should not print to $stdout" do
63
+ @stdout.should be_empty
64
+ end
65
+
66
+ it "should not print to $stderr (with warnings on)" do
67
+ @stderr.should be_empty
68
+ end
69
+
70
+ end
71
+
72
+ # Helpers
73
+ class EmbeddedHTML < RequestLogAnalyzer::Output::Base
74
+ def print(str)
75
+ @io << str
76
+ end
77
+ alias_method :<<, :print
78
+
79
+ def puts(str = "")
80
+ @io << "#{str}<br/>\n"
81
+ end
82
+
83
+ def title(title)
84
+ @io.puts(tag(:h2, title))
85
+ end
86
+
87
+ def line(*font)
88
+ @io.puts(tag(:hr))
89
+ end
90
+
91
+ def link(text, url = nil)
92
+ url = text if url.nil?
93
+ tag(:a, text, :href => url)
94
+ end
95
+
96
+ def table(*columns, &block)
97
+ rows = Array.new
98
+ yield(rows)
99
+
100
+ @io << tag(:table, :cellspacing => 0) do |content|
101
+ if table_has_header?(columns)
102
+ content << tag(:tr) do
103
+ columns.map { |col| tag(:th, col[:title]) }.join("\n")
104
+ end
105
+ end
106
+
107
+ odd = false
108
+ rows.each do |row|
109
+ odd = !odd
110
+ content << tag(:tr) do
111
+ if odd
112
+ row.map { |cell| tag(:td, cell, :class => "alt") }.join("\n")
113
+ else
114
+ row.map { |cell| tag(:td, cell) }.join("\n")
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ def header
122
+ end
123
+
124
+ def footer
125
+ @io << tag(:hr) << tag(:p, "Powered by request-log-analyzer v#{RequestLogAnalyzer::VERSION}")
126
+ end
127
+
128
+ private
129
+
130
+ def tag(tag, content = nil, attributes = nil)
131
+ if block_given?
132
+ attributes = content.nil? ? "" : " " + content.map { |(key, value)| "#{key}=\"#{value}\"" }.join(" ")
133
+ content_string = ""
134
+ content = yield(content_string)
135
+ content = content_string unless content_string.empty?
136
+ "<#{tag}#{attributes}>#{content}</#{tag}>"
137
+ else
138
+ attributes = attributes.nil? ? "" : " " + attributes.map { |(key, value)| "#{key}=\"#{value}\"" }.join(" ")
139
+ if content.nil?
140
+ "<#{tag}#{attributes} />"
141
+ else
142
+ if content.class == Float
143
+ "<#{tag}#{attributes}><div class='color_bar' style=\"width:#{(content*200).floor}px;\"/></#{tag}>"
144
+ else
145
+ "<#{tag}#{attributes}>#{content}</#{tag}>"
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
151
+
@@ -0,0 +1,52 @@
1
+ module RequestLogAnalyzer::Spec::Helpers
2
+
3
+ # Create or return a new TestingFormat
4
+ def testing_format
5
+ @testing_format ||= TestingFormat.create
6
+ end
7
+
8
+ # Load a log file from the fixture folder
9
+ def log_fixture(name, extention = "log")
10
+ File.dirname(__FILE__) + "/../fixtures/#{name}.#{extention}"
11
+ end
12
+
13
+ # Creates a log file given some lines
14
+ def log_stream(*lines)
15
+ StringIO.new(lines.join("\n") + "\n")
16
+ end
17
+
18
+ # Request loopback
19
+ def request(fields, format = testing_format)
20
+ if fields.kind_of?(Array)
21
+ format.request(*fields)
22
+ else
23
+ format.request(fields)
24
+ end
25
+ end
26
+
27
+ # Run a specific command
28
+ # Used to call request-log-analyzer through binary
29
+ def run(arguments)
30
+ binary = "#{File.dirname(__FILE__)}/../../bin/request-log-analyzer"
31
+ arguments = arguments.join(' ') if arguments.kind_of?(Array)
32
+
33
+ output = []
34
+ IO.popen("#{binary} #{arguments}") do |pipe|
35
+ output = pipe.readlines
36
+ end
37
+ $?.exitstatus.should == 0
38
+ output
39
+ end
40
+
41
+ # Cleanup all temporary files generated by specs
42
+ def cleanup_temp_files!
43
+ Dir["#{File.dirname(__FILE__)}/../../tmp/spec.*tmp"].each do |file|
44
+ File.unlink(file)
45
+ end
46
+ end
47
+
48
+ # Return a filename that can be used as temporary file in specs
49
+ def temp_output_file(file_type)
50
+ "#{File.dirname(__FILE__)}/../../tmp/spec.#{file_type}.tmp"
51
+ end
52
+ end