Skip to content

Commit

Permalink
Merge pull request #126 from spikegrobstein/feature/log_directory
Browse files Browse the repository at this point in the history
Rla now accepts directories containing log files.
  • Loading branch information
barttenbrinke committed Oct 7, 2012
2 parents b256c46 + b34a539 commit 3a5f0f7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/request_log_analyzer/source/log_parser.rb
Expand Up @@ -118,6 +118,11 @@ def decompress_file?(filename)
# <tt>options</tt>:: A Hash of options that will be pased to parse_io. # <tt>options</tt>:: A Hash of options that will be pased to parse_io.
def parse_file(file, options = {}, &block) def parse_file(file, options = {}, &block)


if File.directory?(file)
parse_files(Dir["#{ file }/*"], options, &block)
return
end

@current_source = File.expand_path(file) @current_source = File.expand_path(file)
@source_changes_handler.call(:started, @current_source) if @source_changes_handler @source_changes_handler.call(:started, @current_source) if @source_changes_handler


Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/s3_logs/2012-10-05-16-18-11-F9AAC5D1A55AEBAD
@@ -0,0 +1,5 @@
300a66dd319290e36b67767f862a7f39072caa70ba33b8d01c4b79ddd8e6d7ef lamestuff.com [05/Oct/2012:15:24:46 +0000] 174.44.160.70 - CE74FF983317B326 REST.GET.OBJECT public/portfolio/22/thumbnail.jpg "GET /lamestuff.com/public/portfolio/22/thumbnail.jpg HTTP/1.1" 200 - 9515 9515 42 41 "http://spike.grobste.in/portfolio" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14" -
300a66dd319290e36b67767f862a7f39072caa70ba33b8d01c4b79ddd8e6d7ef lamestuff.com [05/Oct/2012:15:25:20 +0000] 174.44.160.70 - D484E1F8E6DE0AAB REST.GET.OBJECT public/projects/46/resume.png "GET /lamestuff.com/public/projects/46/resume.png HTTP/1.1" 200 - 510856 510856 85 74 "http://spike.grobste.in/portfolio/show?name=lamestuff.com-%282007%29" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14" -
300a66dd319290e36b67767f862a7f39072caa70ba33b8d01c4b79ddd8e6d7ef lamestuff.com [05/Oct/2012:15:25:25 +0000] 174.44.160.70 - E5C48446A01539FC REST.GET.OBJECT public/projects/3/gameboy.jpg "GET /lamestuff.com/public/projects/3/gameboy.jpg HTTP/1.1" 200 - 37458 37458 57 55 "http://spike.grobste.in/project/classic-console-art" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14" -
300a66dd319290e36b67767f862a7f39072caa70ba33b8d01c4b79ddd8e6d7ef lamestuff.com [05/Oct/2012:15:25:27 +0000] 174.44.160.70 - CD6CC6713DE2254A REST.GET.OBJECT public/projects/115/xmas-card-2006-d.jpg "GET /lamestuff.com/public/projects/115/xmas-card-2006-d.jpg HTTP/1.1" 200 - 89892 89892 58 55 "http://spike.grobste.in/portfolio/show?name=xmas-2006" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14" -
300a66dd319290e36b67767f862a7f39072caa70ba33b8d01c4b79ddd8e6d7ef lamestuff.com [05/Oct/2012:15:25:31 +0000] 174.44.160.70 - B8B9CBDE2EFE51F3 REST.GET.OBJECT public/projects/34/Tim_Horton-Window-Coffee-ba.jpg "GET /lamestuff.com/public/projects/34/Tim_Horton-Window-Coffee-ba.jpg HTTP/1.1" 200 - 27376 27376 41 40 "http://spike.grobste.in/project/tim-horton's-at-the-nyse" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14" -
3 changes: 3 additions & 0 deletions spec/fixtures/s3_logs/2012-10-05-16-26-06-15314AF7F0651839
@@ -0,0 +1,3 @@
300a66dd319290e36b67767f862a7f39072caa70ba33b8d01c4b79ddd8e6d7ef lamestuff.com [05/Oct/2012:15:24:46 +0000] 174.44.160.70 - FC6B8CCFF3510D92 REST.GET.OBJECT public/portfolio/29/thumbnail.jpg "GET /lamestuff.com/public/portfolio/29/thumbnail.jpg HTTP/1.1" 200 - 6240 6240 40 39 "http://spike.grobste.in/portfolio" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14" -
300a66dd319290e36b67767f862a7f39072caa70ba33b8d01c4b79ddd8e6d7ef lamestuff.com [05/Oct/2012:15:25:27 +0000] 174.44.160.70 - 6908D7E8249F8AB0 REST.GET.OBJECT public/projects/114/xmas-card-2006-c.jpg "GET /lamestuff.com/public/projects/114/xmas-card-2006-c.jpg HTTP/1.1" 200 - 99874 99874 51 47 "http://spike.grobste.in/portfolio/show?name=xmas-2006" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14" -
300a66dd319290e36b67767f862a7f39072caa70ba33b8d01c4b79ddd8e6d7ef lamestuff.com [05/Oct/2012:15:25:30 +0000] 174.44.160.70 - 41804BB9A626C674 REST.GET.OBJECT public/projects/28/Tim_Horton_Counter__3x12_.jpg "GET /lamestuff.com/public/projects/28/Tim_Horton_Counter__3x12_.jpg HTTP/1.1" 200 - 22256 22256 93 91 "http://spike.grobste.in/project/tim-horton's-at-the-nyse" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14" -
5 changes: 5 additions & 0 deletions spec/integration/command_line_usage_spec.rb
Expand Up @@ -87,4 +87,9 @@
output = run("--format rails - < #{log_fixture(:rails_1x)}") output = run("--format rails - < #{log_fixture(:rails_1x)}")
output.any? { |line| /^Parsed requests\:\s*4\s/ =~ line }.should be_true output.any? { |line| /^Parsed requests\:\s*4\s/ =~ line }.should be_true
end end

it "should accept a directory as a commandline option" do
output = run("#{log_directory_fixture("s3_logs")} --format amazon_s3")
output.any? { |line| /^Parsed requests:\s*8\s/ =~ line }.should be_true
end
end end
11 changes: 8 additions & 3 deletions spec/lib/helpers.rb
Expand Up @@ -10,6 +10,11 @@ def log_fixture(name, extention = "log")
File.dirname(__FILE__) + "/../fixtures/#{name}.#{extention}" File.dirname(__FILE__) + "/../fixtures/#{name}.#{extention}"
end end


# directory of logs
def log_directory_fixture(name)
File.dirname(__FILE__) + "/../fixtures/#{name}"
end

# Creates a log file given some lines # Creates a log file given some lines
def log_snippet(*lines) def log_snippet(*lines)
StringIO.new(lines.join("\n") << "\n") StringIO.new(lines.join("\n") << "\n")
Expand Down Expand Up @@ -49,12 +54,12 @@ def cleanup_temp_files!
def temp_output_file(file_type) def temp_output_file(file_type)
File.expand_path("#{File.dirname(__FILE__)}/../../tmp/spec.#{file_type}.tmp") File.expand_path("#{File.dirname(__FILE__)}/../../tmp/spec.#{file_type}.tmp")
end end

# Check if a given string can be found in the given file # Check if a given string can be found in the given file
# Returns the line number if found, nil otherwise # Returns the line number if found, nil otherwise
def find_string_in_file(string, file, options = {}) def find_string_in_file(string, file, options = {})
return nil unless File.exists?(file) return nil unless File.exists?(file)

line_counter = 0 line_counter = 0


File.open( file ) do |io| File.open( file ) do |io|
Expand All @@ -66,7 +71,7 @@ def find_string_in_file(string, file, options = {})
return line_counter if line.include? string return line_counter if line.include? string
} }
end end

return nil return nil
end end
end end

0 comments on commit 3a5f0f7

Please sign in to comment.