Kouhei Sutou
null+****@clear*****
Thu Jan 10 12:27:45 JST 2013
Kouhei Sutou 2013-01-10 12:27:45 +0900 (Thu, 10 Jan 2013) New Revision: 22d82d1c551894ff8f0563eb542bb3b182573e4f https://github.com/groonga/groonga/commit/22d82d1c551894ff8f0563eb542bb3b182573e4f Log: Remove global grn_qlog_path variable Use grn_default_query_logger_set_path() and grn_default_query_logger_get_path() instead. This is incompatible change but nobody uses grn_qlog_path. Modified files: include/groonga.h lib/ctx.c src/groonga.c Modified: include/groonga.h (+2 -0) =================================================================== --- include/groonga.h 2013-01-10 12:18:34 +0900 (2c80f0e) +++ include/groonga.h 2013-01-10 12:27:45 +0900 (2ce78cf) @@ -2113,6 +2113,8 @@ GRN_API grn_bool grn_query_logger_pass(grn_ctx *ctx, unsigned int flag); GRN_API void grn_default_query_logger_set_flags(unsigned int flags); GRN_API unsigned int grn_default_query_logger_get_flags(void); +GRN_API void grn_default_query_logger_set_path(const char *path); +GRN_API const char *grn_default_query_logger_get_path(void); #define GRN_QUERY_LOG(ctx, flag, mark, format, ...) do {\ if (grn_query_logger_pass(ctx, flag)) {\ Modified: lib/ctx.c (+46 -11) =================================================================== --- lib/ctx.c 2013-01-10 12:18:34 +0900 (6590eaa) +++ lib/ctx.c 2013-01-10 12:27:45 +0900 (817d150) @@ -680,7 +680,6 @@ grn_ctx_set_finalizer(grn_ctx *ctx, grn_proc_func *finalizer) } grn_timeval grn_starttime; -const char *grn_qlog_path = NULL; static char *default_logger_path = NULL; static FILE *default_logger_file = NULL; @@ -915,6 +914,7 @@ logger_fin(grn_ctx *ctx) } +static char *default_query_logger_path = NULL; static FILE *default_query_logger_file = NULL; static grn_critical_section default_query_logger_lock; @@ -923,10 +923,10 @@ default_query_logger_log(grn_ctx *ctx, unsigned int flag, const char *timestamp, const char *info, const char *message, void *user_data) { - if (grn_qlog_path) { + if (default_query_logger_path) { CRITICAL_SECTION_ENTER(default_query_logger_lock); if (!default_query_logger_file) { - default_query_logger_file = fopen(grn_qlog_path, "a"); + default_query_logger_file = fopen(default_query_logger_path, "a"); } if (default_query_logger_file) { fprintf(default_query_logger_file, "%s|%s%s\n", timestamp, info, message); @@ -940,7 +940,7 @@ static void default_query_logger_close(grn_ctx *ctx, void *user_data) { GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_DESTINATION, " ", - "query log will be closed: <%s>", grn_qlog_path); + "query log will be closed: <%s>", default_query_logger_path); CRITICAL_SECTION_ENTER(default_query_logger_lock); if (default_query_logger_file) { fclose(default_query_logger_file); @@ -952,10 +952,10 @@ default_query_logger_close(grn_ctx *ctx, void *user_data) static void default_query_logger_reopen(grn_ctx *ctx, void *user_data) { - if (grn_qlog_path) { - default_query_logger_close(ctx, user_data); + default_query_logger_close(ctx, user_data); + if (default_query_logger_path) { GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_DESTINATION, " ", - "query log is opened: <%s>", grn_qlog_path); + "query log is opened: <%s>", default_query_logger_path); } } @@ -999,6 +999,26 @@ grn_default_query_logger_get_flags(void) } void +grn_default_query_logger_set_path(const char *path) +{ + if (default_query_logger_path) { + free(default_query_logger_path); + } + + if (path) { + default_query_logger_path = strdup(path); + } else { + default_query_logger_path = NULL; + } +} + +const char * +grn_default_query_logger_get_path(void) +{ + return default_query_logger_path; +} + +void grn_log_reopen(grn_ctx *ctx) { grn_logger_reopen(ctx); @@ -1013,6 +1033,23 @@ grn_query_logger_reopen(grn_ctx *ctx) } } +static void +query_logger_init(void) +{ + memcpy(¤t_query_logger, &default_query_logger, sizeof(grn_query_logger)); + CRITICAL_SECTION_INIT(default_query_logger_lock); +} + +static void +query_logger_fin(grn_ctx *ctx) +{ + grn_query_logger_fin(ctx); + if (default_query_logger_path) { + free(default_query_logger_path); + } + CRITICAL_SECTION_FIN(default_query_logger_lock); +} + static grn_obj grn_true_, grn_false_, grn_null_; grn_obj *grn_true, *grn_false, *grn_null; @@ -1049,9 +1086,8 @@ grn_init(void) grn_rc rc; grn_ctx *ctx = &grn_gctx; logger_init(); - memcpy(¤t_query_logger, &default_query_logger, sizeof(grn_query_logger)); + query_logger_init(); CRITICAL_SECTION_INIT(grn_glock); - CRITICAL_SECTION_INIT(default_query_logger_lock); grn_gtick = 0; ctx->next = ctx; ctx->prev = ctx; @@ -1214,7 +1250,7 @@ grn_fin(void) GRN_GFREE(ctx); } } - grn_query_logger_fin(ctx); + query_logger_fin(ctx); grn_cache_fin(); grn_token_fin(); grn_normalizer_fin(); @@ -1224,7 +1260,6 @@ grn_fin(void) grn_com_fin(); GRN_LOG(ctx, GRN_LOG_NOTICE, "grn_fin (%d)", alloc_count); logger_fin(ctx); - CRITICAL_SECTION_FIN(default_query_logger_lock); CRITICAL_SECTION_FIN(grn_glock); return GRN_SUCCESS; } Modified: src/groonga.c (+2 -4) =================================================================== --- src/groonga.c 2013-01-10 12:18:34 +0900 (8a497c0) +++ src/groonga.c 2013-01-10 12:27:45 +0900 (ef792a4) @@ -1837,9 +1837,7 @@ init_default_settings(void) init_default_hostname(); default_log_path = grn_default_logger_get_path(); - if (grn_qlog_path) { - default_query_log_path = grn_qlog_path; - } + default_query_log_path = grn_default_query_logger_get_path(); default_config_path = getenv("GRN_CONFIG_PATH"); if (!default_config_path) { @@ -2252,7 +2250,7 @@ main(int argc, char **argv) } if (query_log_path_arg) { - grn_qlog_path = query_log_path_arg; + grn_default_query_logger_set_path(query_log_path_arg); } if (log_level_arg) { -------------- next part -------------- HTML����������������������������...Download