[Groonga-commit] groonga/groonga [master] Remove global grn_log_path variable

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jan 10 12:08:41 JST 2013


Kouhei Sutou	2013-01-10 12:08:41 +0900 (Thu, 10 Jan 2013)

  New Revision: 0afc9183ce10ed5920887506ca019a99b0a431cd
  https://github.com/groonga/groonga/commit/0afc9183ce10ed5920887506ca019a99b0a431cd

  Log:
    Remove global grn_log_path variable
    
    Use grn_default_logger_set_path() and grn_default_logger_get_path()
    instead.
    
    This is incompatible change but nobody uses grn_log_path.

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

  Modified: include/groonga.h (+2 -0)
===================================================================
--- include/groonga.h    2013-01-10 11:33:20 +0900 (7318f42)
+++ include/groonga.h    2013-01-10 12:08:41 +0900 (2c80f0e)
@@ -2081,6 +2081,8 @@ GRN_API int grn_logger_pass(grn_ctx *ctx, grn_log_level 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(void);
+GRN_API void grn_default_logger_set_path(const char *path);
+GRN_API const char *grn_default_logger_get_path(void);
 
 #define GRN_LOG(ctx,level,...) do {\
   if (grn_logger_pass(ctx, level)) {\

  Modified: lib/ctx.c (+52 -16)
===================================================================
--- lib/ctx.c    2013-01-10 11:33:20 +0900 (66a48ef)
+++ lib/ctx.c    2013-01-10 12:08:41 +0900 (cc21f8b)
@@ -680,9 +680,9 @@ grn_ctx_set_finalizer(grn_ctx *ctx, grn_proc_func *finalizer)
 }
 
 grn_timeval grn_starttime;
-const char *grn_log_path = GRN_LOG_PATH;
 const char *grn_qlog_path = NULL;
 
+static char *default_logger_path = NULL;
 static FILE *default_logger_file = NULL;
 static grn_critical_section default_logger_lock;
 
@@ -692,10 +692,10 @@ default_logger_log(grn_ctx *ctx, grn_log_level level,
                    const char *message, const char *location, void *user_data)
 {
   const char slev[] = " EACewnid-";
-  if (grn_log_path) {
+  if (default_logger_path) {
     CRITICAL_SECTION_ENTER(default_logger_lock);
     if (!default_logger_file) {
-      default_logger_file = fopen(grn_log_path, "a");
+      default_logger_file = fopen(default_logger_path, "a");
     }
     if (default_logger_file) {
       if (location && *location) {
@@ -714,16 +714,14 @@ default_logger_log(grn_ctx *ctx, grn_log_level level,
 static void
 default_logger_reopen(grn_ctx *ctx, void *user_data)
 {
-  if (grn_log_path) {
-    GRN_LOG(ctx, GRN_LOG_NOTICE, "log will be closed.");
-    CRITICAL_SECTION_ENTER(default_logger_lock);
-    if (default_logger_file) {
-      fclose(default_logger_file);
-      default_logger_file = NULL;
-    }
-    CRITICAL_SECTION_LEAVE(default_logger_lock);
-    GRN_LOG(ctx, GRN_LOG_NOTICE, "log opened.");
+  GRN_LOG(ctx, GRN_LOG_NOTICE, "log will be closed.");
+  CRITICAL_SECTION_ENTER(default_logger_lock);
+  if (default_logger_file) {
+    fclose(default_logger_file);
+    default_logger_file = NULL;
   }
+  CRITICAL_SECTION_LEAVE(default_logger_lock);
+  GRN_LOG(ctx, GRN_LOG_NOTICE, "log opened.");
 }
 
 static void
@@ -771,6 +769,46 @@ grn_default_logger_get_max_level(void)
 }
 
 void
+grn_default_logger_set_path(const char *path)
+{
+  if (default_logger_path) {
+    free(default_logger_path);
+  }
+
+  if (path) {
+    default_logger_path = strdup(path);
+  } else {
+    default_logger_path = NULL;
+  }
+}
+
+const char *
+grn_default_logger_get_path(void)
+{
+  return default_logger_path;
+}
+
+static void
+logger_init(void)
+{
+  if (!default_logger_path) {
+    default_logger_path = strdup(GRN_LOG_PATH);
+  }
+  memcpy(&current_logger, &default_logger, sizeof(grn_logger));
+  CRITICAL_SECTION_INIT(default_logger_lock);
+}
+
+static void
+logger_fin(grn_ctx *ctx)
+{
+  grn_logger_fin(ctx);
+  if (default_logger_path) {
+    free(default_logger_path);
+  }
+  CRITICAL_SECTION_FIN(default_logger_lock);
+}
+
+void
 grn_logger_reopen(grn_ctx *ctx)
 {
   if (current_logger.reopen) {
@@ -911,10 +949,9 @@ grn_init(void)
 {
   grn_rc rc;
   grn_ctx *ctx = &grn_gctx;
-  memcpy(&current_logger, &default_logger, sizeof(grn_logger));
+  logger_init();
   memcpy(&current_query_logger, &default_query_logger, sizeof(grn_query_logger));
   CRITICAL_SECTION_INIT(grn_glock);
-  CRITICAL_SECTION_INIT(default_logger_lock);
   CRITICAL_SECTION_INIT(default_query_logger_lock);
   grn_gtick = 0;
   ctx->next = ctx;
@@ -1087,9 +1124,8 @@ grn_fin(void)
   grn_ctx_fin(ctx);
   grn_com_fin();
   GRN_LOG(ctx, GRN_LOG_NOTICE, "grn_fin (%d)", alloc_count);
-  grn_logger_fin(ctx);
+  logger_fin(ctx);
   CRITICAL_SECTION_FIN(default_query_logger_lock);
-  CRITICAL_SECTION_FIN(default_logger_lock);
   CRITICAL_SECTION_FIN(grn_glock);
   return GRN_SUCCESS;
 }

  Modified: lib/ctx.h (+0 -1)
===================================================================
--- lib/ctx.h    2013-01-10 11:33:20 +0900 (b062c64)
+++ lib/ctx.h    2013-01-10 12:08:41 +0900 (2552fe6)
@@ -379,7 +379,6 @@ extern int grn_pagesize;
 extern grn_critical_section grn_glock;
 extern uint32_t grn_gtick;
 extern grn_obj *grn_true, *grn_false, *grn_null;
-GRN_VAR const char *grn_log_path;
 GRN_VAR const char *grn_qlog_path;
 
 #define GRN_CTX_ALLOCATED                            (0x80)

  Modified: src/groonga.c (+3 -5)
===================================================================
--- src/groonga.c    2013-01-10 11:33:20 +0900 (1e779b1)
+++ src/groonga.c    2013-01-10 12:08:41 +0900 (8a497c0)
@@ -1,6 +1,6 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
-  Copyright(C) 2009-2012 Brazil
+  Copyright(C) 2009-2013 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -1836,9 +1836,7 @@ init_default_settings(void)
 
   init_default_hostname();
 
-  if (grn_log_path) {
-    default_log_path = grn_log_path;
-  }
+  default_log_path = grn_default_logger_get_path();
   if (grn_qlog_path) {
     default_query_log_path = grn_qlog_path;
   }
@@ -2250,7 +2248,7 @@ main(int argc, char **argv)
   }
 
   if (log_path_arg) {
-    grn_log_path = log_path_arg;
+    grn_default_logger_set_path(log_path_arg);
   }
 
   if (query_log_path_arg) {
-------------- next part --------------
HTML����������������������������...
Download 



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