[Groonga-commit] groonga/groonga at 3e7abe4 [master] Support using ctx->errbuf in GRN_PLUGIN_ERROR() arguments

Back to archive index

Kouhei Sutou null+****@clear*****
Sat May 21 18:38:11 JST 2016


Kouhei Sutou	2016-05-21 18:38:11 +0900 (Sat, 21 May 2016)

  New Revision: 3e7abe4ef08b81c5e67a70bc4015338d2c758727
  https://github.com/groonga/groonga/commit/3e7abe4ef08b81c5e67a70bc4015338d2c758727

  Message:
    Support using ctx->errbuf in GRN_PLUGIN_ERROR() arguments

  Modified files:
    include/groonga/plugin.h
    lib/plugin.c

  Modified: include/groonga/plugin.h (+0 -3)
===================================================================
--- include/groonga/plugin.h    2016-05-21 18:37:30 +0900 (ea5f237)
+++ include/groonga/plugin.h    2016-05-21 18:38:11 +0900 (f8fdca6)
@@ -113,9 +113,6 @@ GRN_API void grn_plugin_logtrace(grn_ctx *ctx, grn_log_level level);
 #define GRN_PLUGIN_SET_ERROR(ctx, level, error_code, ...) do { \
   grn_plugin_set_error(ctx, level, error_code, \
                        __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); \
-  GRN_LOG(ctx, level, __VA_ARGS__); \
-  grn_plugin_backtrace(ctx); \
-  grn_plugin_logtrace(ctx, level); \
 } while (0)
 
 #define GRN_PLUGIN_ERROR(ctx, error_code, ...) \

  Modified: lib/plugin.c (+24 -0)
===================================================================
--- lib/plugin.c    2016-05-21 18:37:30 +0900 (3148c98)
+++ lib/plugin.c    2016-05-21 18:38:11 +0900 (0cd5c12)
@@ -1093,18 +1093,41 @@ grn_plugin_set_error(grn_ctx *ctx, grn_log_level level, grn_rc error_code,
                      const char *file, int line, const char *func,
                      const char *format, ...)
 {
+  char old_error_message[GRN_CTX_MSGSIZE];
+
   ctx->errlvl = level;
   ctx->rc = error_code;
   ctx->errfile = file;
   ctx->errline = line;
   ctx->errfunc = func;
 
+  grn_strcpy(old_error_message, GRN_CTX_MSGSIZE, ctx->errbuf);
+
   {
     va_list ap;
     va_start(ap, format);
     grn_ctx_logv(ctx, format, ap);
     va_end(ap);
   }
+
+  if (grn_ctx_impl_should_log(ctx)) {
+    grn_ctx_impl_set_current_error_message(ctx);
+    if (grn_logger_pass(ctx, level)) {
+      char new_error_message[GRN_CTX_MSGSIZE];
+      grn_strcpy(new_error_message, GRN_CTX_MSGSIZE, ctx->errbuf);
+      grn_strcpy(ctx->errbuf, GRN_CTX_MSGSIZE, old_error_message);
+      {
+        va_list ap;
+        va_start(ap, format);
+        grn_logger_putv(ctx, level, file, line, func, format, ap);
+        va_end(ap);
+      }
+      grn_strcpy(ctx->errbuf, GRN_CTX_MSGSIZE, new_error_message);
+    }
+    if (level <= GRN_LOG_ERROR) {
+      grn_plugin_logtrace(ctx, level);
+    }
+  }
 }
 
 void
@@ -1123,6 +1146,7 @@ void
 grn_plugin_logtrace(grn_ctx *ctx, grn_log_level level)
 {
   if (level <= GRN_LOG_ERROR) {
+    grn_plugin_backtrace(ctx);
     LOGTRACE(ctx, level);
   }
 }
-------------- next part --------------
HTML����������������������������...
Download 



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