[Groonga-commit] groonga/groonga-query-log [master] Extractor: add method to extract commands in logs specified their paths or ARGF

Zurück zum Archiv-Index

Haruka Yoshihara null+****@clear*****
Tue Dec 18 14:28:53 JST 2012


Haruka Yoshihara	2012-12-18 14:28:53 +0900 (Tue, 18 Dec 2012)

  New Revision: 34df7e753eb9523b3416a5a5f6def84b0d5e9901
  https://github.com/groonga/groonga-query-log/commit/34df7e753eb9523b3416a5a5f6def84b0d5e9901

  Log:
    Extractor: add method to extract commands in logs specified their paths or ARGF

  Modified files:
    lib/groonga/query-log/extractor.rb

  Modified: lib/groonga/query-log/extractor.rb (+17 -15)
===================================================================
--- lib/groonga/query-log/extractor.rb    2012-12-18 13:43:56 +0900 (ec67b2b)
+++ lib/groonga/query-log/extractor.rb    2012-12-18 14:28:53 +0900 (96fd4d5)
@@ -42,8 +42,6 @@ module Groonga
       end
 
       def run(*arguments)
-        log = nil
-
         begin
           log_paths = @option_parser.parse!(arguments)
         rescue OptionParser::ParseError
@@ -55,25 +53,17 @@ module Groonga
             raise(NoInputError, "Error: Please specify input log files.")
           end
           log = ARGF
-        end
-
-        if****@optio*****_path
-          output = File.open(@options.output_path, "w")
         else
-          output = $stdout
+          log = log_paths
         end
 
-        if log.nil?
-          log_paths.each do |log_path|
-            File.open(log_path) do |log_file|
-              extract(log_file, output)
-            end
+        if****@optio*****_path
+          File.open(@options.output_path, "w") do |output|
+            extract(log, output)
           end
         else
-          extract(log, output)
+          extract(log, $stdout)
         end
-
-        output.close if File.file?(output)
       end
 
       private
@@ -132,6 +122,18 @@ module Groonga
       end
 
       def extract(log, output)
+        if log.instance_of?(Array)
+          log.each do |log_path|
+            File.open(log_path) do |log_file|
+              extract_command(log_file, output)
+            end
+          end
+        else
+          extract_command(log, output)
+        end
+      end
+
+      def extract_command(log, output)
         parser = Groonga::QueryLog::Parser.new
         parser.parse(log) do |statistic|
           command = statistic.command
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index