[Groonga-commit] groonga/groonga [master] Support changing default logger's max level before grn_init()

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Aug 20 18:02:03 JST 2012


Kouhei Sutou	2012-08-20 18:02:03 +0900 (Mon, 20 Aug 2012)

  New Revision: 25b31d77a8ae4825cda9a1332b776b410db988f1
  https://github.com/groonga/groonga/commit/25b31d77a8ae4825cda9a1332b776b410db988f1

  Merged 58a1b20: Merge pull request #27 from groonga/support-default-logger-max-level-change

  Log:
    Support changing default logger's max level before grn_init()
    
    grn_init() logs some messages such as vm.overcommit_memory related
    messages. vm.overcommit_memory related messages uses INFO log level.
    The messages never be logged because the default max log level is
    NOTICE and the default max log level can't be changed before grn_init().

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

  Modified: include/groonga.h (+3 -0)
===================================================================
--- include/groonga.h    2012-08-17 16:29:32 +0900 (3030d86)
+++ include/groonga.h    2012-08-20 18:02:03 +0900 (428a2b1)
@@ -2039,6 +2039,9 @@ GRN_API int grn_logger_pass(grn_ctx *ctx, grn_log_level level);
 #define GRN_LOG_DEFAULT_LEVEL GRN_LOG_NOTICE
 #endif /* GRN_LOG_DEFAULT_LEVEL */
 
+GRN_API void grn_default_logger_set_max_level(grn_log_level level);
+GRN_API grn_log_level grn_default_logger_get_max_level();
+
 #define GRN_LOG(ctx,level,...) do {\
   if (grn_logger_pass(ctx, level)) {\
     grn_logger_put(ctx, (level), __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); \

  Modified: lib/ctx.c (+12 -0)
===================================================================
--- lib/ctx.c    2012-08-17 16:29:32 +0900 (06f3a4d)
+++ lib/ctx.c    2012-08-20 18:02:03 +0900 (eb7c0da)
@@ -732,6 +732,18 @@ static grn_logger_info default_logger = {
 static const grn_logger_info *grn_logger = &default_logger;
 
 void
+grn_default_logger_set_max_level(grn_log_level level)
+{
+  default_logger.max_level = level;
+}
+
+grn_log_level
+grn_default_logger_get_max_level(void)
+{
+  return default_logger.max_level;
+}
+
+void
 grn_log_reopen(grn_ctx *ctx)
 {
   if (grn_logger != &default_logger) {

  Modified: src/groonga.c (+14 -13)
===================================================================
--- src/groonga.c    2012-08-17 16:29:32 +0900 (2707076)
+++ src/groonga.c    2012-08-20 18:02:03 +0900 (1f6277c)
@@ -2234,6 +2234,20 @@ main(int argc, char **argv)
     grn_qlog_path = query_log_path_arg;
   }
 
+  if (log_level_arg) {
+    const char * const end = log_level_arg + strlen(log_level_arg);
+    const char *rest = NULL;
+    const int value = grn_atoi(log_level_arg, end, &rest);
+    if (end != rest || value < 0 || value > 9) {
+      fprintf(stderr, "invalid log level: <%s>\n", log_level_arg);
+      return EXIT_FAILURE;
+    }
+    log_level = value;
+  } else {
+    log_level = default_log_level;
+  }
+  grn_default_logger_set_max_level(log_level);
+
   if (max_num_threads_arg) {
     const char * const end = max_num_threads_arg + strlen(max_num_threads_arg);
     const char *rest = NULL;
@@ -2368,19 +2382,6 @@ main(int argc, char **argv)
     default_match_escalation_threshold = default_default_match_escalation_threshold;
   }
 
-  if (log_level_arg) {
-    const char * const end = log_level_arg + strlen(log_level_arg);
-    const char *rest = NULL;
-    const int value = grn_atoi(log_level_arg, end, &rest);
-    if (end != rest || value < 0 || value > 9) {
-      fprintf(stderr, "invalid log level: <%s>\n", log_level_arg);
-      return EXIT_FAILURE;
-    }
-    log_level = value;
-  } else {
-    log_level = default_log_level;
-  }
-
   if (cache_limit_arg) {
     const char * const end = cache_limit_arg + strlen(cache_limit_arg);
     const char *rest = NULL;
-------------- next part --------------
HTML����������������������������...
Download 



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