[Groonga-commit] groonga/groonga [split-query-logger] Split query logger from logger

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Oct 21 23:54:54 JST 2012


Kouhei Sutou	2012-10-21 23:54:54 +0900 (Sun, 21 Oct 2012)

  New Revision: 6980fbf326c33fee7b1ec4bae566a52ea6060c8d
  https://github.com/groonga/groonga/commit/6980fbf326c33fee7b1ec4bae566a52ea6060c8d

  Log:
    Split query logger from logger
    
    LAP(":", "select(%d)", nhits) ->
    GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
                  ":", "select(%d)", nhits)

  Modified files:
    include/groonga.h
    lib/ctx.c
    lib/ctx.h
    lib/expr.c
    lib/proc.c
    lib/str.h
    plugins/suggest/suggest.c
    test/unit/core/test-log.c

  Modified: include/groonga.h (+46 -0)
===================================================================
--- include/groonga.h    2012-10-19 17:05:32 +0900 (b872f34)
+++ include/groonga.h    2012-10-21 23:54:54 +0900 (245aaa3)
@@ -151,6 +151,23 @@ typedef enum {
   GRN_LOG_DUMP
 } grn_log_level;
 
+/* query log flags */
+#define GRN_QUERY_LOG_NONE        (0x00)
+#define GRN_QUERY_LOG_COMMAND     (0x01<<0)
+#define GRN_QUERY_LOG_RESULT_CODE (0x01<<1)
+#define GRN_QUERY_LOG_DESTINATION (0x01<<2)
+#define GRN_QUERY_LOG_CACHE       (0x01<<3)
+#define GRN_QUERY_LOG_SIZE        (0x01<<4)
+#define GRN_QUERY_LOG_SCORE       (0x01<<5)
+#define GRN_QUERY_LOG_ALL\
+  (GRN_QUERY_LOG_COMMAND |\
+   GRN_QUERY_LOG_RESULT_CODE |\
+   GRN_QUERY_LOG_DESTINATION |\
+   GRN_QUERY_LOG_CACHE |\
+   GRN_QUERY_LOG_SIZE |\
+   GRN_QUERY_LOG_SCORE)
+#define GRN_QUERY_LOG_DEFAULT     GRN_QUERY_LOG_ALL
+
 typedef enum {
   GRN_CONTENT_NONE = 0,
   GRN_CONTENT_TSV,
@@ -2048,6 +2065,35 @@ GRN_API grn_log_level grn_default_logger_get_max_level();
   }\
 } while (0)
 
+typedef struct _grn_query_logger_info grn_query_logger_info;
+
+struct _grn_query_logger_info {
+  unsigned int flags;
+  grn_user_data *user_data;
+  void (*log)(grn_ctx *ctx, unsigned int flag,
+              const char *timestamp, const char *info, const char *message,
+              grn_user_data *user_data);
+  void (*reopen)(grn_ctx *ctx, grn_user_data *user_data);
+  void (*fin)(grn_ctx *ctx, grn_user_data *user_data);
+};
+
+GRN_API grn_rc grn_query_logger_info_set(grn_ctx *ctx, const grn_query_logger_info *info);
+
+GRN_API void grn_query_logger_put(grn_ctx *ctx, unsigned int flag,
+                                  const char *mark,
+                                  const char *format, ...) GRN_ATTRIBUTE_PRINTF(4);
+
+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);
+
+#define GRN_QUERY_LOG(ctx, flag, mark, format, ...) do {\
+  if (grn_query_logger_pass(ctx, flag)) {\
+    grn_query_logger_put(ctx, (flag), (mark), format, __VA_ARGS__);\
+  }\
+} while (0)
+
 /* grn_bulk */
 
 #define GRN_BULK_BUFSIZE (sizeof(grn_obj) - sizeof(grn_obj_header))

  Modified: lib/ctx.c (+187 -51)
===================================================================
--- lib/ctx.c    2012-10-19 17:05:32 +0900 (bcca962)
+++ lib/ctx.c    2012-10-21 23:54:54 +0900 (4177e80)
@@ -683,7 +683,6 @@ const char *grn_log_path = GRN_LOG_PATH;
 const char *grn_qlog_path = NULL;
 
 static FILE *default_logger_fp = NULL;
-static FILE *default_logger_qlog_fp = NULL;
 static grn_critical_section grn_logger_lock;
 
 static void
@@ -691,35 +690,21 @@ default_logger_func(int level, const char *time, const char *title,
                     const char *msg, const char *location, void *func_arg)
 {
   const char slev[] = " EACewnid-";
-  if (level > GRN_LOG_NONE) {
-    if (grn_log_path) {
-      CRITICAL_SECTION_ENTER(grn_logger_lock);
-      if (!default_logger_fp) {
-        default_logger_fp = fopen(grn_log_path, "a");
-      }
-      if (default_logger_fp) {
-        if (location && *location) {
-          fprintf(default_logger_fp, "%s|%c|%s %s %s\n",
-                  time, *(slev + level), title, msg, location);
-        } else {
-          fprintf(default_logger_fp, "%s|%c|%s %s\n", time, *(slev + level), title, msg);
-        }
-        fflush(default_logger_fp);
-      }
-      CRITICAL_SECTION_LEAVE(grn_logger_lock);
+  if (grn_log_path) {
+    CRITICAL_SECTION_ENTER(grn_logger_lock);
+    if (!default_logger_fp) {
+      default_logger_fp = fopen(grn_log_path, "a");
     }
-  } else {
-    if (grn_qlog_path) {
-      CRITICAL_SECTION_ENTER(grn_logger_lock);
-      if (!default_logger_qlog_fp) {
-        default_logger_qlog_fp = fopen(grn_qlog_path, "a");
-      }
-      if (default_logger_qlog_fp) {
-        fprintf(default_logger_qlog_fp, "%s|%s\n", time, msg);
-        fflush(default_logger_qlog_fp);
+    if (default_logger_fp) {
+      if (location && *location) {
+        fprintf(default_logger_fp, "%s|%c|%s %s %s\n",
+                time, *(slev + level), title, msg, location);
+      } else {
+        fprintf(default_logger_fp, "%s|%c|%s %s\n", time, *(slev + level), title, msg);
       }
-      CRITICAL_SECTION_LEAVE(grn_logger_lock);
+      fflush(default_logger_fp);
     }
+    CRITICAL_SECTION_LEAVE(grn_logger_lock);
   }
 }
 
@@ -744,35 +729,102 @@ grn_default_logger_get_max_level(void)
   return default_logger.max_level;
 }
 
-void
-grn_log_reopen(grn_ctx *ctx)
+
+static FILE *default_query_logger_file = NULL;
+static grn_critical_section grn_query_logger_lock;
+
+static void
+default_query_logger_log(grn_ctx *ctx, unsigned int flag,
+                         const char *timestamp, const char *info,
+                         const char *message, grn_user_data *user_data)
 {
-  if (grn_logger != &default_logger) {
-    ERR(GRN_FUNCTION_NOT_IMPLEMENTED,
-        "grn_log_reopen() is not implemented with a custom grn_logger.");
-    return;
+  if (grn_qlog_path) {
+    CRITICAL_SECTION_ENTER(grn_query_logger_lock);
+    if (!default_query_logger_file) {
+      default_query_logger_file = fopen(grn_qlog_path, "a");
+    }
+    if (default_query_logger_file) {
+      fprintf(default_query_logger_file, "%s|%s%s\n", timestamp, info, message);
+      fflush(default_query_logger_file);
+    }
+    CRITICAL_SECTION_LEAVE(grn_query_logger_lock);
   }
+}
 
-  if (grn_log_path) {
-    GRN_LOG(ctx, GRN_LOG_NOTICE, "log will be closed.");
-    CRITICAL_SECTION_ENTER(grn_logger_lock);
-    if (default_logger_fp) {
-      fclose(default_logger_fp);
-      default_logger_fp = NULL;
-    }
-    CRITICAL_SECTION_LEAVE(grn_logger_lock);
-    GRN_LOG(ctx, GRN_LOG_NOTICE, "log opened.");
+static void
+default_query_logger_close(grn_ctx *ctx, grn_user_data *user_data)
+{
+  GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_DESTINATION, " ",
+                "query log will be closed: <%s>", grn_qlog_path);
+  CRITICAL_SECTION_ENTER(grn_query_logger_lock);
+  if (default_query_logger_file) {
+    fclose(default_query_logger_file);
+    default_query_logger_file = NULL;
   }
+  CRITICAL_SECTION_LEAVE(grn_query_logger_lock);
+}
 
+static void
+default_query_logger_reopen(grn_ctx *ctx, grn_user_data *user_data)
+{
   if (grn_qlog_path) {
-    GRN_LOG(ctx, GRN_LOG_NONE, "query log will be closed.");
-    CRITICAL_SECTION_ENTER(grn_logger_lock);
-    if (default_logger_qlog_fp) {
-      fclose(default_logger_qlog_fp);
-      default_logger_qlog_fp = NULL;
+    default_query_logger_close(ctx, user_data);
+    GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_DESTINATION, " ",
+                  "query log is opened: <%s>", grn_qlog_path);
+  }
+}
+
+static void
+default_query_logger_fin(grn_ctx *ctx, grn_user_data *user_data)
+{
+  if (default_query_logger_file) {
+    default_query_logger_close(ctx, user_data);
+  }
+}
+
+static grn_query_logger_info default_query_logger = {
+  GRN_QUERY_LOG_DEFAULT,
+  NULL,
+  default_query_logger_log,
+  default_query_logger_reopen,
+  default_query_logger_fin
+};
+
+static const grn_query_logger_info *grn_query_logger = &default_query_logger;
+
+void
+grn_default_query_logger_set_flags(unsigned int flags)
+{
+  default_query_logger.flags = flags;
+}
+
+unsigned int
+grn_default_query_logger_get_flags(void)
+{
+  return default_query_logger.flags;
+}
+
+void
+grn_log_reopen(grn_ctx *ctx)
+{
+  if (grn_logger == &default_logger) {
+    if (grn_log_path) {
+      GRN_LOG(ctx, GRN_LOG_NOTICE, "log will be closed.");
+      CRITICAL_SECTION_ENTER(grn_logger_lock);
+      if (default_logger_fp) {
+        fclose(default_logger_fp);
+        default_logger_fp = NULL;
+      }
+      CRITICAL_SECTION_LEAVE(grn_logger_lock);
+      GRN_LOG(ctx, GRN_LOG_NOTICE, "log opened.");
     }
-    CRITICAL_SECTION_LEAVE(grn_logger_lock);
-    GRN_LOG(ctx, GRN_LOG_NONE, "query log opened.");
+  } else {
+    ERR(GRN_FUNCTION_NOT_IMPLEMENTED,
+        "grn_log_reopen() is not implemented with a custom grn_logger.");
+  }
+
+  if (grn_query_logger->reopen) {
+    grn_query_logger->reopen(ctx, grn_query_logger->user_data);
   }
 }
 
@@ -812,8 +864,10 @@ grn_init(void)
   grn_rc rc;
   grn_ctx *ctx = &grn_gctx;
   grn_logger = &default_logger;
+  grn_query_logger = &default_query_logger;
   CRITICAL_SECTION_INIT(grn_glock);
   CRITICAL_SECTION_INIT(grn_logger_lock);
+  CRITICAL_SECTION_INIT(grn_query_logger_lock);
   grn_gtick = 0;
   ctx->next = ctx;
   ctx->prev = ctx;
@@ -972,6 +1026,7 @@ grn_fin(void)
       GRN_GFREE(ctx);
     }
   }
+  grn_query_logger_fin(ctx);
   grn_cache_fin();
   grn_token_fin();
   grn_plugins_fin();
@@ -980,6 +1035,7 @@ grn_fin(void)
   grn_com_fin();
   GRN_LOG(ctx, GRN_LOG_NOTICE, "grn_fin (%d)", alloc_count);
   grn_logger_fin();
+  CRITICAL_SECTION_FIN(grn_query_logger_lock);
   CRITICAL_SECTION_FIN(grn_logger_lock);
   CRITICAL_SECTION_FIN(grn_glock);
   return GRN_SUCCESS;
@@ -1419,7 +1475,8 @@ grn_ctx_send(grn_ctx *ctx, const char *str, unsigned int str_len, int flags)
         ctx->impl->mime_type = "application/json";
         ctx->impl->output_type = GRN_CONTENT_JSON;
         grn_timeval_now(ctx, &ctx->impl->tv);
-        GRN_LOG(ctx, GRN_LOG_NONE, "%p|>%.*s", ctx, str_len, str);
+        GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_COMMAND,
+                      ">", "%.*s", str_len, str);
         if (str_len && *str == '/') {
           expr = grn_ctx_qe_exec_uri(ctx, str + 1, str_len - 1);
         } else {
@@ -1430,7 +1487,8 @@ grn_ctx_send(grn_ctx *ctx, const char *str, unsigned int str_len, int flags)
       if (ctx->impl->qe_next) {
         ERRCLR(ctx);
       } else {
-        LAP("<", "rc=%d", ctx->rc);
+        GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_RESULT_CODE,
+                      "<", "rc=%d", ctx->rc);
       }
     output :
       if (!ERRP(ctx, GRN_CRIT)) {
@@ -2400,6 +2458,84 @@ grn_logger_put(grn_ctx *ctx, grn_log_level level,
 }
 
 void
+grn_query_logger_fin(grn_ctx *ctx)
+{
+  if (grn_query_logger->fin) {
+    grn_query_logger->fin(ctx, grn_query_logger->user_data);
+  }
+}
+
+grn_rc
+grn_qury_logger_info_set(grn_ctx *ctx, const grn_query_logger_info *info)
+{
+  if (info) {
+    grn_query_logger = info;
+  } else {
+    grn_query_logger = &default_query_logger;
+  }
+  return GRN_SUCCESS;
+}
+
+grn_bool
+grn_query_logger_pass(grn_ctx *ctx, unsigned int flag)
+{
+  return grn_query_logger->flags & flag;
+}
+
+#define TIMESTAMP_BUFFER_SIZE    TBUFSIZE
+/* 8+a(%p) + 1(|) + 1(mark) + 15(elapsed time) = 25+a */
+#define INFO_BUFFER_SIZE         40
+#define MESSAGE_BUFFER_SIZE      MBUFSIZE
+
+void
+grn_query_logger_put(grn_ctx *ctx, unsigned int flag, const char *mark,
+                     const char *format, ...)
+{
+  char timestamp[TIMESTAMP_BUFFER_SIZE];
+  char info[INFO_BUFFER_SIZE];
+  char message[MESSAGE_BUFFER_SIZE];
+
+  {
+    grn_timeval tv;
+    timestamp[0] = '\0';
+    grn_timeval_now(ctx, &tv);
+    grn_timeval2str(ctx, &tv, timestamp);
+  }
+
+  if (flag & (GRN_QUERY_LOG_COMMAND | GRN_QUERY_LOG_DESTINATION)) {
+    snprintf(info, INFO_BUFFER_SIZE - 1, "%p|%s", ctx, mark);
+    info[INFO_BUFFER_SIZE - 1] = '\0';
+  } else {
+    grn_timeval tv;
+    uint64_t elapsed_time;
+    grn_timeval_now(ctx, &tv);
+    elapsed_time =
+      (uint64_t)(tv.tv_sec - ctx->impl->tv.tv_sec) * GRN_TIME_NSEC_PER_SEC +
+      (tv.tv_nsec - ctx->impl->tv.tv_nsec);
+
+    snprintf(info, INFO_BUFFER_SIZE - 1,
+             "%p|%s%015" GRN_FMT_INT64U " ", ctx, mark, elapsed_time);
+    info[INFO_BUFFER_SIZE - 1] = '\0';
+  }
+
+  {
+    va_list args;
+    va_start(args, format);
+    vsnprintf(message, MESSAGE_BUFFER_SIZE - 1, format, args);
+    va_end(args);
+    message[MESSAGE_BUFFER_SIZE - 1] = '\0';
+  }
+
+  if (grn_query_logger->log) {
+    grn_query_logger->log(ctx, flag, timestamp, info, message,
+                          grn_query_logger->user_data);
+  } else {
+    default_query_logger_log(ctx, flag, timestamp, info, message,
+                             grn_query_logger->user_data);
+  }
+}
+
+void
 grn_assert(grn_ctx *ctx, int cond, const char* file, int line, const char* func)
 {
   if (!cond) {

  Modified: lib/ctx.h (+3 -10)
===================================================================
--- lib/ctx.h    2012-10-19 17:05:32 +0900 (9c5cf9d)
+++ lib/ctx.h    2012-10-21 23:54:54 +0900 (287f98e)
@@ -404,16 +404,6 @@ extern grn_timeval grn_starttime;
 #define GRN_TIME_NSEC_TO_USEC(nsec) ((nsec) / GRN_TIME_NSEC_PER_USEC)
 #define GRN_TIME_USEC_TO_NSEC(usec) ((usec) * GRN_TIME_NSEC_PER_USEC)
 
-#define LAP(prefix,format,...) do {\
-  uint64_t et;\
-  grn_timeval tv;\
-  grn_timeval_now(ctx, &tv);\
-  et = (uint64_t)(tv.tv_sec - ctx->impl->tv.tv_sec) * GRN_TIME_NSEC_PER_SEC\
-    + (tv.tv_nsec - ctx->impl->tv.tv_nsec);\
-  GRN_LOG(ctx, GRN_LOG_NONE, "%p|" prefix "%015" GRN_FMT_INT64U " " format,\
-          ctx, et, __VA_ARGS__);\
-} while (0)
-
 GRN_API grn_rc grn_timeval_now(grn_ctx *ctx, grn_timeval *tv);
 GRN_API grn_rc grn_timeval2str(grn_ctx *ctx, grn_timeval *tv, char *buf);
 grn_rc grn_str2timeval(const char *str, uint32_t str_len, grn_timeval *tv);
@@ -423,6 +413,9 @@ void grn_ctx_qe_fin(grn_ctx *ctx);
 void grn_ctx_loader_clear(grn_ctx *ctx);
 void grn_log_reopen(grn_ctx *ctx);
 
+void grn_logger_fin(void);
+void grn_query_logger_fin(grn_ctx *ctx);
+
 GRN_API grn_rc grn_ctx_sendv(grn_ctx *ctx, int argc, char **argv, int flags);
 GRN_API void grn_ctx_set_next_expr(grn_ctx *ctx, grn_obj *expr);
 

  Modified: lib/expr.c (+2 -1)
===================================================================
--- lib/expr.c    2012-10-19 17:05:32 +0900 (0d7d96a)
+++ lib/expr.c    2012-10-21 23:54:54 +0900 (c79c1b0)
@@ -4328,7 +4328,8 @@ grn_table_select(grn_ctx *ctx, grn_obj *table, grn_obj *expr,
             grn_table_select_(ctx, table, expr, v, res, si->logical_op);
           }
         }
-        LAP(":", "filter(%d)", grn_table_size(ctx, res));
+        GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
+                      ":", "filter(%d)", grn_table_size(ctx, res));
       }
       for (i = 0; i < n; i++) {
         scan_info *si = sis[i];

  Modified: lib/proc.c (+13 -6)
===================================================================
--- lib/proc.c    2012-10-19 17:05:32 +0900 (47078fa)
+++ lib/proc.c    2012-10-21 23:54:54 +0900 (3aa2043)
@@ -506,7 +506,9 @@ grn_select(grn_ctx *ctx, const char *table, unsigned int table_len,
     if ((cache = grn_cache_fetch(ctx, cache_key, cache_key_size))) {
       GRN_TEXT_PUT(ctx, outbuf, GRN_TEXT_VALUE(cache), GRN_TEXT_LEN(cache));
       grn_cache_unref(cache_key, cache_key_size);
-      LAP(":", "cache(%" GRN_FMT_LLD ")", (long long int)GRN_TEXT_LEN(cache));
+      GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_CACHE,
+                    ":", "cache(%" GRN_FMT_LLD ")",
+                    (long long int)GRN_TEXT_LEN(cache));
       return ctx->rc;
     }
   }
@@ -596,7 +598,8 @@ grn_select(grn_ctx *ctx, const char *table, unsigned int table_len,
       res = table_;
     }
     nhits = res ? grn_table_size(ctx, res) : 0;
-    LAP(":", "select(%d)", nhits);
+    GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
+                  ":", "select(%d)", nhits);
 
     if (res) {
       uint32_t ngkeys;
@@ -629,7 +632,8 @@ grn_select(grn_ctx *ctx, const char *table, unsigned int table_len,
           }
           grn_obj_unlink(ctx, scorer_);
         }
-        LAP(":", "score(%d)", nhits);
+        GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
+                      ":", "score(%d)", nhits);
       }
 
       grn_normalize_offset_and_limit(ctx, nhits, &offset, &limit);
@@ -639,7 +643,8 @@ grn_select(grn_ctx *ctx, const char *table, unsigned int table_len,
         if ((sorted = grn_table_create(ctx, NULL, 0, NULL,
                                        GRN_OBJ_TABLE_NO_KEY, NULL, res))) {
           grn_table_sort(ctx, res, offset, limit, sorted, keys, nkeys);
-          LAP(":", "sort(%d)", limit);
+          GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
+                        ":", "sort(%d)", limit);
           GRN_OBJ_FORMAT_INIT(&format, nhits, 0, limit, offset);
           format.flags =
             GRN_OBJ_FORMAT_WITH_COLUMN_NAMES|
@@ -681,7 +686,8 @@ grn_select(grn_ctx *ctx, const char *table, unsigned int table_len,
           GRN_OBJ_FORMAT_FIN(ctx, &format);
         }
       }
-      LAP(":", "output(%d)", limit);
+      GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
+                    ":", "output(%d)", limit);
       if (!ctx->rc && drilldown_len) {
         uint32_t i;
         grn_table_group_result g = {NULL, 0, 0, 1, GRN_TABLE_GROUP_CALC_COUNT, 0};
@@ -734,7 +740,8 @@ grn_select(grn_ctx *ctx, const char *table, unsigned int table_len,
               }
               grn_obj_unlink(ctx, g.table);
             }
-            LAP(":", "drilldown(%d)", nhits);
+            GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
+                          ":", "drilldown(%d)", nhits);
           }
           grn_table_sort_key_close(ctx, gkeys, ngkeys);
         }

  Modified: lib/str.h (+0 -2)
===================================================================
--- lib/str.h    2012-10-19 17:05:32 +0900 (7bcb955)
+++ lib/str.h    2012-10-21 23:54:54 +0900 (2353bed)
@@ -77,8 +77,6 @@ grn_id grn_btoi(char *b);
 
 grn_rc grn_substring(grn_ctx *ctx, char **str, char **str_end, int start, int end, grn_encoding encoding);
 
-void grn_logger_fin(void);
-
 GRN_API int grn_charlen_(grn_ctx *ctx, const char *str, const char *end, grn_encoding encoding);
 GRN_API grn_str *grn_str_open_(grn_ctx *ctx, const char *str, unsigned int str_len, int flags, grn_encoding encoding);
 

  Modified: plugins/suggest/suggest.c (+8 -4)
===================================================================
--- plugins/suggest/suggest.c    2012-10-19 17:05:32 +0900 (3d7e1fa)
+++ plugins/suggest/suggest.c    2012-10-21 23:54:54 +0900 (a71f29f)
@@ -246,7 +246,8 @@ output(grn_ctx *ctx, grn_obj *table, grn_obj *res, grn_id tid,
     }
     if ((keys = grn_table_sort_key_from_str(ctx, sortby_val, sortby_len, res, &nkeys))) {
       grn_table_sort(ctx, res, offset, limit, sorted, keys, nkeys);
-      LAP(":", "sort(%d)", limit);
+      GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
+                    ":", "sort(%d)", limit);
       GRN_OBJ_FORMAT_INIT(&format, grn_table_size(ctx, res), 0, limit, offset);
       format.flags =
         GRN_OBJ_FORMAT_WITH_COLUMN_NAMES|
@@ -380,7 +381,8 @@ correct(grn_ctx *ctx, grn_obj *items, grn_obj *items_boost,
     max_score = cooccurrence_search(ctx, items, items_boost, tid, res, CORRECT,
                                     frequency_threshold,
                                     conditional_probability_threshold);
-    LAP(":", "cooccur(%d)", max_score);
+    GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SCORE,
+                  ":", "cooccur(%d)", max_score);
     if (GRN_TEXT_LEN(query) &&
         ((similar_search_mode == GRN_SUGGEST_SEARCH_YES) ||
          (similar_search_mode == GRN_SUGGEST_SEARCH_AUTO &&
@@ -396,7 +398,8 @@ correct(grn_ctx *ctx, grn_obj *items, grn_obj *items_boost,
           grn_ii_select(ctx, (grn_ii *)index, TEXT_VALUE_LEN(query),
                         (grn_hash *)res, GRN_OP_OR, &optarg);
           grn_obj_unlink(ctx, index);
-          LAP(":", "similar(%d)", grn_table_size(ctx, res));
+          GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
+                        ":", "similar(%d)", grn_table_size(ctx, res));
           {
             grn_hash_cursor *hc = grn_hash_cursor_open(ctx, (grn_hash *)res, NULL,
                                                        0, NULL, 0, 0, -1, 0);
@@ -427,7 +430,8 @@ correct(grn_ctx *ctx, grn_obj *items, grn_obj *items_boost,
               grn_hash_cursor_close(ctx, hc);
             }
           }
-          LAP(":", "filter(%d)", grn_table_size(ctx, res));
+          GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
+                        ":", "filter(%d)", grn_table_size(ctx, res));
           {
             /* exec _score -= edit_distance(_key, "query string") for all records */
             grn_obj *var;

  Modified: test/unit/core/test-log.c (+14 -9)
===================================================================
--- test/unit/core/test-log.c    2012-10-19 17:05:32 +0900 (5fb7f7e)
+++ test/unit/core/test-log.c    2012-10-21 23:54:54 +0900 (3b5315b)
@@ -92,10 +92,13 @@ test_invalid_char(void)
   assert_send_command("load --table Users --input_type json\n"
                       "{\"name\": \"groonga\" @ \"desc\" \"search engine\"}\n"
                       "");
-  log = g_list_next(grn_collect_logger_get_messages(logger));
-  cut_assert_equal_string("ignored invalid char('@') at", g_list_nth_data(log, 0));
-  cut_assert_equal_string("{\"name\": \"groonga\" @", g_list_nth_data(log, 1));
-  cut_assert_equal_string("                   ^", g_list_nth_data(log, 2));
+  log = (GList *)grn_collect_logger_get_messages(logger);
+  cut_assert_equal_string("ignored invalid char('@') at",
+                          g_list_nth_data(log, 0));
+  cut_assert_equal_string("{\"name\": \"groonga\" @",
+                          g_list_nth_data(log, 1));
+  cut_assert_equal_string("                   ^",
+                          g_list_nth_data(log, 2));
 }
 
 void
@@ -109,8 +112,9 @@ test_no_key(void)
   assert_send_command("load --table Users --input_type json\n"
                       "{\"info\" \"search engine\"}\n"
                       "");
-  log = g_list_next(grn_collect_logger_get_messages(logger));
-  cut_assert_equal_string("neither _key nor _id is assigned", g_list_nth_data(log, 0));
+  log = (GList *)grn_collect_logger_get_messages(logger);
+  cut_assert_equal_string("neither _key nor _id is assigned",
+                          g_list_nth_data(log, 0));
 }
 
 void
@@ -124,8 +128,9 @@ test_duplicated_key(void)
   assert_send_command("load --table Users --input_type json\n"
                       "{\"_key\": \"groonga\", \"_id\": 1}\n"
                       "");
-  log = g_list_next(grn_collect_logger_get_messages(logger));
-  cut_assert_equal_string("duplicated key columns: _key and _id", g_list_nth_data(log, 0));
+  log = (GList *)grn_collect_logger_get_messages(logger);
+  cut_assert_equal_string("duplicated key columns: _key and _id",
+                          g_list_nth_data(log, 0));
 }
 
 void
@@ -139,6 +144,6 @@ test_invalid_column(void)
   assert_send_command("load --table Users --input_type json\n"
                       "{\"_key\": \"groonga\", \"info\" \"search engine\"}\n"
                       "");
-  log = g_list_next(grn_collect_logger_get_messages(logger));
+  log = (GList *)grn_collect_logger_get_messages(logger);
   cut_assert_equal_string("invalid column('info')", g_list_nth_data(log, 0));
 }
-------------- next part --------------
HTML����������������������������...
下载 



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