Re: Identifying a message in emit_log_hook.

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: Identifying a message in emit_log_hook.
Дата
Msg-id CAFj8pRCg0GpZwVB3ZdAw8YriWnZ+Ty6twQOCqpmXgcTvYXX-mQ@mail.gmail.com
обсуждение исходный текст
Ответ на Identifying a message in emit_log_hook.  (Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>)
Ответы Re: Identifying a message in emit_log_hook.  (Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>)
Список pgsql-hackers
Hi

2016-02-16 10:47 GMT+01:00 Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>:
Hello.

I'm planning to change the error level of a specific error
message.  We can use emit_log_hook for this purpose but we have
no reliable means to identify what a message is.

For messages without valid sqlerrcode, filename:lineno could be
used to identify but lineno is too unstable.  One possible and
most straightforward way to solve this is defining identifiers
covering all error messages but such identifiers are too hard to
manage.  ErrorData.message could also be used but NLS translation
and placeholders prevent it from being identified by simple means
like strcmp(3).

As a solution for this problem, I'd like to porpose to have an
additional member in the struct ErrorData to hold a message id,
that is, the format string for errmsg(). This is not best but
useful enough.

It is somewhat a crude way, but the attached small patch would
do.

Is there any opinions or suggestions?

It looks like workaround. The fixing missing sqlerrcode is much better.

Regards

Pavel

 

regards,

--
Kyotaro Horiguchi
NTT Open Source Software Center

diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 9005b26..2d13101 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -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);
diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h
index 326896f..4df76da 100644
--- a/src/include/utils/elog.h
+++ b/src/include/utils/elog.h
@@ -354,6 +354,7 @@ typedef struct ErrorData
        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 */
        char       *schema_name;        /* name of schema */
        char       *table_name;         /* name of table */
        char       *column_name;        /* name of column */


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Kyotaro HORIGUCHI
Дата:
Сообщение: Identifying a message in emit_log_hook.
Следующее
От: Fabien COELHO
Дата:
Сообщение: Re: extend pgbench expressions with functions