lib/request_log_analyzer/controller.rb in request-log-analyzer-1.12.2 vs lib/request_log_analyzer/controller.rb in request-log-analyzer-1.12.3

- old
+ new

@@ -95,11 +95,11 @@ # Build a new controller. # Returns a new RequestLogAnalyzer::Controller object. # # Options # * <tt>:after</tt> Drop all requests after this date (Date, DateTime, Time, or a String in "YYYY-MM-DD hh:mm:ss" format) - # * <tt>:aggregator</tt> Array of aggregators (ATM: STRINGS OR SYMBOLS ONLY! - Defaults to [:summarizer]). + # * <tt>:aggregator</tt> Array of aggregators (Strings or Symbols for the builtin aggregators or a RequestLogAnalyzer::Aggregator class - Defaults to [:summarizer]). # * <tt>:boring</tt> Do not show color on STDOUT (Defaults to false). # * <tt>:before</tt> Drop all requests before this date (Date, DateTime, Time or a String in "YYYY-MM-DD hh:mm:ss" format) # * <tt>:database</tt> Database file to insert encountered requests to. # * <tt>:debug</tt> Enables echo aggregator which will echo each request analyzed. # * <tt>:file</tt> Filestring, File or StringIO. @@ -114,10 +114,11 @@ # * <tt>:reset_database</tt> Reset the database before starting. # * <tt>:select</tt> Select specific {:field => :value} combination (expects a single hash). # * <tt>:source_files</tt> Source files to analyze. Provide either File, array of files or STDIN. # * <tt>:yaml</tt> Output to YAML file. # * <tt>:silent</tt> Minimal output automatically implies :no_progress + # * <tt>:source</tt> The class to instantiate to grab the requestes, must be a RequestLogAnalyzer::Source::Base descendant. (Defaults to RequestLogAnalyzer::Source::LogParser) # # === Example # RequestLogAnalyzer::Controller.build( # :output => :HTML, # :mail => 'root@localhost', @@ -136,10 +137,11 @@ options[:report_width] ||= 80 options[:report_amount] ||= 20 options[:report_sort] ||= 'sum,mean' options[:boring] ||= false options[:silent] ||= false + options[:source] ||= RequestLogAnalyzer::Source::LogParser options[:no_progress] = true if options[:silent] # Deprecation warnings if options[:dump] @@ -180,13 +182,13 @@ file_format = RequestLogAnalyzer::FileFormat.load(options[:format]) end # Kickstart the controller controller = - Controller.new(RequestLogAnalyzer::Source::LogParser.new(file_format, - :source_files => options[:source_files], - :parse_strategy => options[:parse_strategy]), + Controller.new(options[:source].new(file_format, + :source_files => options[:source_files], + :parse_strategy => options[:parse_strategy]), { :output => output_instance, :database => options[:database], # FUGLY! :yaml => options[:yaml], :reset_database => options[:reset_database], :no_progress => options[:no_progress], @@ -218,11 +220,11 @@ controller.add_filter(:field, :mode => :select, :field => field, :value => value) end end # register aggregators - options[:aggregator].each { |agg| controller.add_aggregator(agg.to_sym) } + options[:aggregator].each { |agg| controller.add_aggregator(agg) } controller.add_aggregator(:summarizer) if options[:aggregator].empty? controller.add_aggregator(:echo) if options[:debug] controller.add_aggregator(:database_inserter) if options[:database] && !options[:aggregator].include?('database') file_format.setup_environment(controller) @@ -282,10 +284,10 @@ end # Adds an aggregator to the controller. The aggregator will be called for every request # that is parsed from the provided sources (see add_source) def add_aggregator(agg) - agg = RequestLogAnalyzer::Aggregator.const_get(RequestLogAnalyzer.to_camelcase(agg)) if agg.kind_of?(Symbol) + agg = RequestLogAnalyzer::Aggregator.const_get(RequestLogAnalyzer.to_camelcase(agg)) if agg.kind_of?(String) || agg.kind_of?(Symbol) @aggregators << agg.new(@source, @options) end alias :>> :add_aggregator