[Groonga-commit] ranguba/chupa-text at e4f662d [master] chupa-text: add --log-output and --log-level options

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jan 6 00:11:35 JST 2014


Kouhei Sutou	2014-01-06 00:11:35 +0900 (Mon, 06 Jan 2014)

  New Revision: e4f662db775ba418f926ec337cc462f0908921e8
  https://github.com/ranguba/chupa-text/commit/e4f662db775ba418f926ec337cc462f0908921e8

  Message:
    chupa-text: add --log-output and --log-level options

  Modified files:
    lib/chupa-text/command/chupa-text.rb

  Modified: lib/chupa-text/command/chupa-text.rb (+38 -0)
===================================================================
--- lib/chupa-text/command/chupa-text.rb    2014-01-06 00:11:13 +0900 (6b0774f)
+++ lib/chupa-text/command/chupa-text.rb    2014-01-06 00:11:35 +0900 (cccbf37)
@@ -89,9 +89,47 @@ module ChupaText
                   "Appends PATH to decomposer load path.") do |path|
           $LOAD_PATH << path
         end
+
+        parser.separator("")
+        parser.separator("Log related options:")
+        parser.on("--log-output=OUTPUT",
+                  "Sets log output.",
+                  "[-(stdout), +(stderr), PATH]",
+                  "(default: +(stderr))") do |output|
+          ENV["CHUPA_TEXT_LOG_OUTPUT"] = output
+          ::ChupaText.logger = nil
+        end
+        parser.on("--log-level=LEVEL", available_log_levels,
+                  "Sets log level.",
+                  "[#{available_log_levels.join(', ')}]",
+                  "(default: #{current_log_level_name})") do |level|
+          ENV["CHUPA_TEXT_LOG_LEVEL"] = level
+          ::ChupaText.logger = nil
+        end
+
         parser
       end
 
+      def available_log_levels
+        [
+          "debug",
+          "info",
+          "warn",
+          "error",
+          "fatal",
+          "unknown",
+        ]
+      end
+
+      def current_log_level_name
+        level = ::ChupaText.logger.level
+        Logger::Severity.constants.each do |name|
+          next if Logger::Severity.const_get(name) != level
+          return name.to_s.downcase
+        end
+        "info"
+      end
+
       def load_decomposers
         Decomposers.enable_all_gems if @enable_gems
         Decomposers.load
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index