]> granicus.if.org Git - postgresql/commitdiff
Allow emit_log_hook to see original message text
authorSimon Riggs <simon@2ndQuadrant.com>
Fri, 11 Mar 2016 09:53:06 +0000 (09:53 +0000)
committerSimon Riggs <simon@2ndQuadrant.com>
Fri, 11 Mar 2016 09:53:06 +0000 (09:53 +0000)
emit_log_hook could only see the translated text, making it harder to identify
which message was being sent. Pass original text to allow the exact message to
be identified, whichever language is used for logging.

Discussion: 20160216.184755.59721141.horiguchi.kyotaro@lab.ntt.co.jp
Author: Kyotaro Horiguchi

src/backend/utils/error/elog.c
src/include/utils/elog.h

index 9005b261cda46fd82d94765f3a1353353d201c81..5b7554b6ea14ba7e86d610c4078e77ecdaa53172 100644 (file)
@@ -801,6 +801,7 @@ errmsg(const char *fmt,...)
        CHECK_STACK_DEPTH();
        oldcontext = MemoryContextSwitchTo(edata->assoc_context);
 
+       edata->message_id = fmt;
        EVALUATE_MESSAGE(edata->domain, message, false, true);
 
        MemoryContextSwitchTo(oldcontext);
@@ -830,6 +831,7 @@ errmsg_internal(const char *fmt,...)
        CHECK_STACK_DEPTH();
        oldcontext = MemoryContextSwitchTo(edata->assoc_context);
 
+       edata->message_id = fmt;
        EVALUATE_MESSAGE(edata->domain, message, false, false);
 
        MemoryContextSwitchTo(oldcontext);
@@ -853,6 +855,7 @@ errmsg_plural(const char *fmt_singular, const char *fmt_plural,
        CHECK_STACK_DEPTH();
        oldcontext = MemoryContextSwitchTo(edata->assoc_context);
 
+       edata->message_id = fmt_singular;
        EVALUATE_MESSAGE_PLURAL(edata->domain, message, false);
 
        MemoryContextSwitchTo(oldcontext);
@@ -1361,6 +1364,7 @@ elog_finish(int elevel, const char *fmt,...)
        recursion_depth++;
        oldcontext = MemoryContextSwitchTo(edata->assoc_context);
 
+       edata->message_id = fmt;
        EVALUATE_MESSAGE(edata->domain, message, false, false);
 
        MemoryContextSwitchTo(oldcontext);
@@ -1420,6 +1424,7 @@ format_elog_string(const char *fmt,...)
 
        oldcontext = MemoryContextSwitchTo(ErrorContext);
 
+       edata->message_id = fmt;
        EVALUATE_MESSAGE(edata->domain, message, false, true);
 
        MemoryContextSwitchTo(oldcontext);
@@ -1458,6 +1463,11 @@ EmitErrorReport(void)
         * where it would have much less information available.  emit_log_hook is
         * intended for custom log filtering and custom log message transmission
         * mechanisms.
+        *
+        * The log hook has access to both the translated and original English
+        * error message text, which is passed through to allow it to be used
+        * as a message identifier. Note that the original text is not available
+        * for detail, detail_log, hint and context text elements.
         */
        if (edata->output_to_server && emit_log_hook)
                (*emit_log_hook) (edata);
index 326896f0204b2ba349b08815f018a6e04b863a56..7d338dd1ceab5bc1f73e0de557891555426683e8 100644 (file)
@@ -349,11 +349,12 @@ typedef struct ErrorData
        const char *domain;                     /* message domain */
        const char *context_domain; /* message domain for context message */
        int                     sqlerrcode;             /* encoded ERRSTATE */
-       char       *message;            /* primary error message */
+       char       *message;            /* primary error message (translated) */
        char       *detail;                     /* detail error message */
        char       *detail_log;         /* detail error message for server log only */
        char       *hint;                       /* hint message */
        char       *context;            /* context message */
+       const char *message_id;         /* message id of .message (original English text) */
        char       *schema_name;        /* name of schema */
        char       *table_name;         /* name of table */
        char       *column_name;        /* name of column */