Skip to content

Commit

Permalink
Merge remote branch 'JEG2/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
barttenbrinke committed Sep 29, 2009
2 parents c7108a3 + d15fb19 commit fc0d34b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
37 changes: 26 additions & 11 deletions lib/request_log_analyzer/controller.rb
Expand Up @@ -84,11 +84,11 @@ def self.build_from_arguments(arguments)
# * <tt>:parse_strategy</tt>
# * <tt>:no_progress</tt>
# * <tt>:output</tt> :fixed_width, :html or Output class. Defaults to fixed width.
# * <tt>:file</tt> Filestring or File
# * <tt>:file</tt> Filestring or File or StringIO
# * <tt>:format</tt> :rails, {:apache => 'FORMATSTRING'}, :merb, etcetera or Format Class. Defaults to :rails.
# * <tt>:source_files</tt> File or STDIN
# * <tt>:after</tt> Drop all requests after this date
# * <tt>:before</tt> Drop all requests before this date
# * <tt>:after</tt> Drop all requests after this date (Date, DateTime, Time, or a String in "YYYY-MM-DD hh:mm:ss" format)
# * <tt>:before</tt> Drop all requests before this date (Date, DateTime, Time, or a String in "YYYY-MM-DD hh:mm:ss" format)
# * <tt>:reject</tt> Reject specific {:field => :value} combination. Expects single hash.
# * <tt>:select</tt> Select specific {:field => :value} combination. Expects single hash.
# * <tt>:aggregator</tt> Array of aggregators (ATM: STRINGS OR SYMBOLS ONLY!). Defaults to [:summarizer
Expand All @@ -111,13 +111,17 @@ def self.build(options)
# Set the output class
output_args = {}
output_object = nil
output_class = RequestLogAnalyzer::Output::const_get(options[:output])
if options[:output].is_a? Class
output_class = options[:output]
else
output_class = RequestLogAnalyzer::Output::const_get(options[:output])
end

output_sort = options[:report_sort].split(',').map { |s| s.to_sym }
output_amount = options[:report_amount] == 'all' ? :all : options[:report_amount].to_i

if options[:file]
output_object = (options[:file].class == File) ? options[:file] : File.new(options[:file], "w+")
output_object = %w[File StringIO].include?(options[:file].class.name) ? options[:file] : File.new(options[:file], "w+")
output_args = {:width => 80, :color => false, :characters => :ascii, :sort => output_sort, :amount => output_amount }
elsif options[:mail]
output_object = RequestLogAnalyzer::Mailer.new(arguments[:mail])
Expand Down Expand Up @@ -147,17 +151,27 @@ def self.build(options)
# register filters
if options[:after] || options[:before]
filter_options = {}
filter_options[:after] = DateTime.parse(options[:after]) if options[:after]
filter_options[:before] = DateTime.parse(options[:before]) if options[:before]
[:after, :before].each do |filter|
case options[filter]
when Date, DateTime, Time
filter_options[filter] = options[filter]
when String
filter_options[filter] = DateTime.parse(options[filter])
end
end
controller.add_filter(:timespan, filter_options)
end

options[:reject].each do |(field, value)|
controller.add_filter(:field, :mode => :reject, :field => field, :value => value)
if options[:reject]
options[:reject].each do |(field, value)|
controller.add_filter(:field, :mode => :reject, :field => field, :value => value)
end
end

options[:select].each do |(field, value)|
controller.add_filter(:field, :mode => :select, :field => field, :value => value)
if options[:reject]
options[:select].each do |(field, value)|
controller.add_filter(:field, :mode => :select, :field => field, :value => value)
end
end

# register aggregators
Expand All @@ -184,6 +198,7 @@ def initialize(source, options = {})
@aggregators = []
@filters = []
@output = options[:output]
@interrupted = false

# Register the request format for this session after checking its validity
raise "Invalid file format!" unless @source.file_format.valid?
Expand Down
2 changes: 2 additions & 0 deletions lib/request_log_analyzer/filter/timespan.rb
Expand Up @@ -9,6 +9,8 @@ class Timespan < Base
attr_reader :before, :after

def initialize(file_format, options = {})
@after = nil
@before = nil
super(file_format, options)
setup_filter
end
Expand Down
1 change: 1 addition & 0 deletions lib/request_log_analyzer/line_definition.rb
Expand Up @@ -38,6 +38,7 @@ def method_missing(name, *args, &block)
def initialize(name, definition = {})
@name = name
@captures = []
@teaser = nil
definition.each { |key, value| self.send("#{key.to_s}=".to_sym, value) }
end

Expand Down
1 change: 0 additions & 1 deletion lib/request_log_analyzer/request.rb
Expand Up @@ -21,7 +21,6 @@ def convert_value(value, capture_definition)
end

def convert_string(value, capture_definition); value; end
def convert_decimal(value, capture_definition); value.to_f; end
def convert_float(value, capture_definition); value.to_f; end
def convert_decimal(value, capture_definition); value.to_f; end
def convert_int(value, capture_definition); value.to_i; end
Expand Down
7 changes: 6 additions & 1 deletion lib/request_log_analyzer/source/log_parser.rb
Expand Up @@ -33,9 +33,12 @@ def initialize(format, options = {})
@parsed_requests = 0
@skipped_lines = 0
@skipped_requests = 0
@current_request = nil
@current_source = nil
@current_file = nil
@current_lineno = nil
@source_files = options[:source_files]
@progress_handler = nil

@options[:parse_strategy] ||= DEFAULT_PARSE_STRATEGY
raise "Unknown parse strategy" unless PARSE_STRATEGIES.include?(@options[:parse_strategy])
Expand All @@ -49,7 +52,9 @@ def each_request(options = {}, &block) # :yields: :request, request

case @source_files
when IO
puts "Parsing from the standard input. Press CTRL+C to finish." # FIXME: not here
if @source_files == $stdin
puts "Parsing from the standard input. Press CTRL+C to finish." # FIXME: not here
end
parse_stream(@source_files, options, &block)
when String
parse_file(@source_files, options, &block)
Expand Down

0 comments on commit fc0d34b

Please sign in to comment.