[Groonga-commit] groonga/groonga at ad847a7 [master] grndb: add --log-path option

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Jun 6 11:18:47 JST 2017


Kouhei Sutou	2017-06-06 11:18:47 +0900 (Tue, 06 Jun 2017)

  New Revision: ad847a741777b6be68a5298065309a923ba80a8b
  https://github.com/groonga/groonga/commit/ad847a741777b6be68a5298065309a923ba80a8b

  Message:
    grndb: add --log-path option
    
    GitHub: fix #702

  Modified files:
    lib/mrb/scripts/command_line_parser.rb
    src/grndb.c

  Modified: lib/mrb/scripts/command_line_parser.rb (+8 -0)
===================================================================
--- lib/mrb/scripts/command_line_parser.rb    2017-06-06 11:17:36 +0900 (0e35ed5)
+++ lib/mrb/scripts/command_line_parser.rb    2017-06-06 11:18:47 +0900 (6de53c1)
@@ -30,6 +30,7 @@ module Groonga
 
     def add_command(name)
       command = Command.new(@program_name, name)
+      setup_common_options(command.options)
       yield(command)
       @commands << command
     end
@@ -81,12 +82,19 @@ module Groonga
     private
     def setup_options
       @options.banner = "Usage: #{@program_name} [OPTIONS]"
+      setup_common_options(@options)
       @options.on("-h", "--help", "Display this help message.",
                   :tail => true) do
         $stdout.puts(help_message)
       end
     end
 
+    def setup_common_options(options)
+      options.string("--log-path",
+                     "Change log path (#{Logger.default_path})",
+                     default: Logger.default_path)
+    end
+
     def find_command(name)
       @commands.find do |command|
         command.name == name

  Modified: src/grndb.c (+31 -1)
===================================================================
--- src/grndb.c    2017-06-06 11:17:36 +0900 (4b21ed1)
+++ src/grndb.c    2017-06-06 11:18:47 +0900 (e308a1f)
@@ -120,8 +120,38 @@ int
 main(int argc, char **argv)
 {
   int exit_code = EXIT_SUCCESS;
+  const char *log_path = GRN_LOG_PATH;
 
-  grn_default_logger_set_path(GRN_LOG_PATH);
+  {
+    int i;
+    for (i = 1; i < argc; i++) {
+      const char *arg = argv[i];
+
+      if (arg[0] != '-') {
+        continue;
+      }
+
+      if (arg[1] == '-' && arg[2] == '\0') {
+        break;
+      }
+
+      if (strcmp(arg, "--log-path") == 0) {
+        if (i + 1 < argc) {
+          log_path = argv[i + 1];
+        } else {
+          break;
+        }
+#define log_path_equal_prefix "--log-path="
+      } else if (strncmp(arg,
+                         log_path_equal_prefix,
+                         strlen(log_path_equal_prefix)) == 0) {
+        log_path = arg + strlen(log_path_equal_prefix);
+      }
+#undef log_path_equal_prefix
+    }
+  }
+
+  grn_default_logger_set_path(log_path);
 
   if (grn_init() != GRN_SUCCESS) {
     return EXIT_FAILURE;
-------------- next part --------------
HTML����������������������������...
다운로드 



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