[Groonga-commit] groonga/groonga at b691dac [master] [WIP] logger: add log-flags option

Back to archive index
Yasuhiro Horimoto null+****@clear*****
Thu Jan 17 17:25:01 JST 2019


Yasuhiro Horimoto	2019-01-17 17:25:01 +0900 (Thu, 17 Jan 2019)

  Revision: b691dac00de338d28ea73cb2f8246fb5da191953
  https://github.com/groonga/groonga/commit/b691dac00de338d28ea73cb2f8246fb5da191953

  Merged aae4d18: Merge pull request #893 from komainu8/add_processid_in_log

  Message:
    [WIP] logger: add log-flags option
    
    TODO: test

  Modified files:
    include/groonga/groonga.h
    lib/logger.c
    src/groonga.c

  Modified: include/groonga/groonga.h (+2 -0)
===================================================================
--- include/groonga/groonga.h    2019-01-12 12:58:38 +0900 (989f06c96)
+++ include/groonga/groonga.h    2019-01-17 17:25:01 +0900 (2ccf88ed8)
@@ -1044,6 +1044,8 @@ struct _grn_logger {
   void (*fin)(grn_ctx *ctx, void *user_data);
 };
 
+GRN_API int grn_log_flags_parse(const char *string);
+
 GRN_API grn_rc grn_logger_set(grn_ctx *ctx, const grn_logger *logger);
 
 GRN_API void grn_logger_set_max_level(grn_ctx *ctx, grn_log_level max_level);

  Modified: lib/logger.c (+34 -0)
===================================================================
--- lib/logger.c    2019-01-12 12:58:38 +0900 (7b333653e)
+++ lib/logger.c    2019-01-17 17:25:01 +0900 (7589a6b71)
@@ -118,6 +118,40 @@ grn_log_level_parse(const char *string, grn_log_level *level)
   }
 }
 
+int
+grn_log_flags_parse(const char *string)
+{
+  const char *string_end = string + strlen(string);
+  int flags = GRN_LOG_TIME|GRN_LOG_MESSAGE;
+
+  if (!string) {
+    return flags;
+  }
+
+  while (string < string_end) {
+    if (*string == '|' || *string == ' ') {
+      string += 1;
+      continue;
+    }
+
+    if (strcmp(string, "+pid")) {
+      flags |= GRN_LOG_PID;
+      string += strlen(string);
+      continue;
+    } else if (strcmp(string, "+threadi-id")) {
+      flags |= GRN_LOG_THREAD_ID;
+      string += strlen(string);
+      continue;
+    } else if (strcmp(string, "+location")) {
+      flags |= GRN_LOG_LOCATION;
+      string += strlen(string);
+      continue;
+    }
+  }
+
+  return flags;
+}
+
 static void
 rotate_log_file(grn_ctx *ctx, const char *current_path)
 {

  Modified: src/groonga.c (+10 -0)
===================================================================
--- src/groonga.c    2019-01-12 12:58:38 +0900 (b6c55bb9a)
+++ src/groonga.c    2019-01-17 17:25:01 +0900 (edb497730)
@@ -3270,6 +3270,7 @@ main(int argc, char **argv)
   const char *default_request_timeout_arg = NULL;
   const char *cache_base_path = NULL;
   const char *listen_backlog_arg = NULL;
+  const char *log_flags_arg = NULL;
   int exit_code = EXIT_SUCCESS;
   int i;
   int flags = 0;
@@ -3313,6 +3314,7 @@ main(int argc, char **argv)
     {'\0', "default-request-timeout", NULL, 0, GETOPT_OP_NONE},
     {'\0', "cache-base-path", NULL, 0, GETOPT_OP_NONE},
     {'\0', "listen-backlog", NULL, 0, GETOPT_OP_NONE},
+    {'\0', "log-flags", NULL, 0, GETOPT_OP_NONE},
     {'\0', NULL, NULL, 0, 0}
   };
   opts[0].arg = &port_arg;
@@ -3340,6 +3342,7 @@ main(int argc, char **argv)
   opts[30].arg = &default_request_timeout_arg;
   opts[31].arg = &cache_base_path;
   opts[32].arg = &listen_backlog_arg;
+  opts[33].arg = &log_flags_arg;
 
   reset_ready_notify_pipe();
 
@@ -3522,6 +3525,13 @@ main(int argc, char **argv)
     grn_default_logger_set_rotate_threshold_size(value);
   }
 
+  if (log_flags_arg) {
+    int log_flags = grn_log_flags_parse(log_flags_arg);
+    if (!log_flags) {
+      grn_default_logger_set_flags(log_flags);
+    }
+  }
+
   if (query_log_path_arg) {
     grn_default_query_logger_set_path(query_log_path_arg);
   }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190117/8aa01046/attachment-0001.html>


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