Identifying a message in emit_log_hook.
От | Kyotaro HORIGUCHI |
---|---|
Тема | Identifying a message in emit_log_hook. |
Дата | |
Msg-id | 20160216.184755.59721141.horiguchi.kyotaro@lab.ntt.co.jp обсуждение исходный текст |
Ответы |
Re: Identifying a message in emit_log_hook.
Re: Identifying a message in emit_log_hook. |
Список | pgsql-hackers |
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? 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 */
В списке pgsql-hackers по дате отправления: