Skip to content

Commit 570bd2b

Browse files
committed
Add capability to suppress CONTEXT: messages to elog machinery.
Hiding context messages usually is not a good idea - except for rather verbose debugging/development utensils like LOG_DEBUG. There the amount of repeated context messages just bloat the log without adding information.
1 parent 4a55931 commit 570bd2b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/backend/utils/error/elog.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,25 @@ errhidestmt(bool hide_stmt)
10811081
return 0; /* return value does not matter */
10821082
}
10831083

1084+
/*
1085+
* errhidestmt --- optionally suppress CONTEXT: field of log entry
1086+
*
1087+
* This should only be used for verbose debugging messages where the repeated
1088+
* inclusion of CONTEXT: bloats the log volume too much.
1089+
*/
1090+
int
1091+
errhidecontext(bool hide_ctx)
1092+
{
1093+
ErrorData *edata = &errordata[errordata_stack_depth];
1094+
1095+
/* we don't bother incrementing recursion_depth */
1096+
CHECK_STACK_DEPTH();
1097+
1098+
edata->hide_ctx = hide_ctx;
1099+
1100+
return 0; /* return value does not matter */
1101+
}
1102+
10841103

10851104
/*
10861105
* errfunction --- add reporting function name to the current error
@@ -2724,7 +2743,8 @@ write_csvlog(ErrorData *edata)
27242743
appendStringInfoChar(&buf, ',');
27252744

27262745
/* errcontext */
2727-
appendCSVLiteral(&buf, edata->context);
2746+
if (!edata->hide_ctx)
2747+
appendCSVLiteral(&buf, edata->context);
27282748
appendStringInfoChar(&buf, ',');
27292749

27302750
/* user query --- only reported if not disabled by the caller */
@@ -2856,7 +2876,7 @@ send_message_to_server_log(ErrorData *edata)
28562876
append_with_tabs(&buf, edata->internalquery);
28572877
appendStringInfoChar(&buf, '\n');
28582878
}
2859-
if (edata->context)
2879+
if (edata->context && !edata->hide_ctx)
28602880
{
28612881
log_line_prefix(&buf, edata);
28622882
appendStringInfoString(&buf, _("CONTEXT: "));

src/include/utils/elog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ errcontext_msg(const char *fmt,...)
221221
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
222222

223223
extern int errhidestmt(bool hide_stmt);
224+
extern int errhidecontext(bool hide_ctx);
224225

225226
extern int errfunction(const char *funcname);
226227
extern int errposition(int cursorpos);
@@ -385,6 +386,7 @@ typedef struct ErrorData
385386
bool output_to_client; /* will report to client? */
386387
bool show_funcname; /* true to force funcname inclusion */
387388
bool hide_stmt; /* true to prevent STATEMENT: inclusion */
389+
bool hide_ctx; /* true to prevent CONTEXT: inclusion */
388390
const char *filename; /* __FILE__ of ereport() call */
389391
int lineno; /* __LINE__ of ereport() call */
390392
const char *funcname; /* __func__ of ereport() call */

0 commit comments

Comments
 (0)