[Groonga-commit] groonga/groonga [master] [suggest] add --n-lines-per-log-file option.

Back to archive index

null+****@clear***** null+****@clear*****
2011年 8月 16日 (火) 19:51:12 JST


Kouhei Sutou	2011-08-16 10:51:12 +0000 (Tue, 16 Aug 2011)

  New Revision: dbc525503e4df314ebef5a06a39c548b2060a05c

  Log:
    [suggest] add --n-lines-per-log-file option.
    
    It supports customize N lines in a log file.

  Modified files:
    src/suggest/groonga_suggest_httpd.c

  Modified: src/suggest/groonga_suggest_httpd.c (+29 -3)
===================================================================
--- src/suggest/groonga_suggest_httpd.c    2011-08-16 10:04:53 +0000 (76acf64)
+++ src/suggest/groonga_suggest_httpd.c    2011-08-16 10:51:12 +0000 (3e2da20)
@@ -51,7 +51,6 @@ grn_rc grn_ctx_close(grn_ctx *ctx);
 
 #define LISTEN_BACKLOG 756
 #define MIN_MAX_FDS 2048
-#define LOG_SPLIT_LINES 1000000
 #define MAX_THREADS 128 /* max 256 */
 
 typedef enum {
@@ -95,6 +94,7 @@ static uint32_t default_max_threads = DEFAULT_MAX_THREADS;
 static uint32_t max_threads;
 static volatile sig_atomic_t loop = 1;
 static grn_obj *db;
+static uint32_t n_lines_per_log_file = 1000000;
 
 static int
 suggest_result(struct evbuffer *res_buf, const char *types, const char *query,
@@ -315,7 +315,9 @@ generic_handler(struct evhttp_request *req, void *arg)
         }
         if (thd->log_file) {
           fprintf(thd->log_file, "%s\n", req->uri);
-          if (++thd->log_count >= LOG_SPLIT_LINES) {
+          thd->log_count++;
+          if (n_lines_per_log_file > 0 &&
+              thd->log_count >= n_lines_per_log_file) {
             close_log_file(thd);
           }
         }
@@ -676,10 +678,13 @@ usage(FILE *output)
     "  -r, --receive-endpoint <receive endpoint> : receive endpoint\n"
     "                                              (ex. tcp://example.com:1235)\n"
     "  -l, --log-base-path <path prefix>         : log path prefix\n"
+    "  --n-lines-per-log-file <lines number>     : number of lines in a log file\n"
+    "                                              use 0 for disabling this\n"
+    "                                              (default: %d)\n"
     "  -d, --daemon                              : daemonize\n"
     "  --disable-max-fd-check                    : disable max FD check on start\n"
     "  -h, --help                                : show this message\n",
-    DEFAULT_PORT, default_max_threads);
+    DEFAULT_PORT, default_max_threads, n_lines_per_log_file);
 }
 
 int
@@ -689,6 +694,7 @@ main(int argc, char **argv)
   const char *max_threads_string = NULL, *port_string = NULL;
   const char *address;
   const char *send_endpoint = NULL, *recv_endpoint = NULL, *log_base_path = NULL;
+  const char *n_lines_per_log_file_string = NULL;
   int n_processed_args, flags = RUN_MODE_ENABLE_MAX_FD_CHECK;
   run_mode mode = run_mode_none;
 
@@ -707,6 +713,7 @@ main(int argc, char **argv)
       {'s', "send-endpoint", NULL, 0, getopt_op_none},
       {'r', "receive-endpoint", NULL, 0, getopt_op_none},
       {'l', "log-base-path", NULL, 0, getopt_op_none},
+      {'\0', "n-lines-per-log-file", NULL, 0, getopt_op_none},
       {'d', "daemon", NULL, run_mode_daemon, getopt_op_update},
       {'\0', "disable-max-fd-check", NULL, RUN_MODE_ENABLE_MAX_FD_CHECK,
        getopt_op_off},
@@ -719,6 +726,7 @@ main(int argc, char **argv)
     opts[5].arg = &send_endpoint;
     opts[6].arg = &recv_endpoint;
     opts[7].arg = &log_base_path;
+    opts[8].arg = &n_lines_per_log_file_string;
 
     n_processed_args = grn_str_getopt(argc, argv, opts, &flags);
   }
@@ -764,6 +772,24 @@ main(int argc, char **argv)
       }
     }
 
+    if (n_lines_per_log_file_string) {
+      int64_t n_lines;
+      n_lines = grn_atoll(n_lines_per_log_file_string,
+                          n_lines_per_log_file_string + strlen(n_lines_per_log_file_string),
+                          NULL);
+      if (n_lines < 0) {
+        print_error("--n-lines-per-log-file must be >= 0: <%s>",
+                    n_lines_per_log_file_string);
+        return(EXIT_FAILURE);
+      }
+      if (n_lines > UINT32_MAX) {
+        print_error("--n-lines-per-log-file must be <= %ld: <%s>",
+                    UINT32_MAX, n_lines_per_log_file_string);
+        return(EXIT_FAILURE);
+      }
+      n_lines_per_log_file = (uint32_t)n_lines;
+    }
+
     if (mode == run_mode_daemon) {
       daemonize();
     }




Groonga-commit メーリングリストの案内
Back to archive index