Commit 570bd2b3 authored by Andres Freund's avatar Andres Freund

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.
parent 4a559319
...@@ -1081,6 +1081,25 @@ errhidestmt(bool hide_stmt) ...@@ -1081,6 +1081,25 @@ errhidestmt(bool hide_stmt)
return 0; /* return value does not matter */ return 0; /* return value does not matter */
} }
/*
* errhidestmt --- optionally suppress CONTEXT: field of log entry
*
* This should only be used for verbose debugging messages where the repeated
* inclusion of CONTEXT: bloats the log volume too much.
*/
int
errhidecontext(bool hide_ctx)
{
ErrorData *edata = &errordata[errordata_stack_depth];
/* we don't bother incrementing recursion_depth */
CHECK_STACK_DEPTH();
edata->hide_ctx = hide_ctx;
return 0; /* return value does not matter */
}
/* /*
* errfunction --- add reporting function name to the current error * errfunction --- add reporting function name to the current error
...@@ -2724,7 +2743,8 @@ write_csvlog(ErrorData *edata) ...@@ -2724,7 +2743,8 @@ write_csvlog(ErrorData *edata)
appendStringInfoChar(&buf, ','); appendStringInfoChar(&buf, ',');
/* errcontext */ /* errcontext */
appendCSVLiteral(&buf, edata->context); if (!edata->hide_ctx)
appendCSVLiteral(&buf, edata->context);
appendStringInfoChar(&buf, ','); appendStringInfoChar(&buf, ',');
/* user query --- only reported if not disabled by the caller */ /* user query --- only reported if not disabled by the caller */
...@@ -2856,7 +2876,7 @@ send_message_to_server_log(ErrorData *edata) ...@@ -2856,7 +2876,7 @@ send_message_to_server_log(ErrorData *edata)
append_with_tabs(&buf, edata->internalquery); append_with_tabs(&buf, edata->internalquery);
appendStringInfoChar(&buf, '\n'); appendStringInfoChar(&buf, '\n');
} }
if (edata->context) if (edata->context && !edata->hide_ctx)
{ {
log_line_prefix(&buf, edata); log_line_prefix(&buf, edata);
appendStringInfoString(&buf, _("CONTEXT: ")); appendStringInfoString(&buf, _("CONTEXT: "));
......
...@@ -221,6 +221,7 @@ errcontext_msg(const char *fmt,...) ...@@ -221,6 +221,7 @@ errcontext_msg(const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
extern int errhidestmt(bool hide_stmt); extern int errhidestmt(bool hide_stmt);
extern int errhidecontext(bool hide_ctx);
extern int errfunction(const char *funcname); extern int errfunction(const char *funcname);
extern int errposition(int cursorpos); extern int errposition(int cursorpos);
...@@ -385,6 +386,7 @@ typedef struct ErrorData ...@@ -385,6 +386,7 @@ typedef struct ErrorData
bool output_to_client; /* will report to client? */ bool output_to_client; /* will report to client? */
bool show_funcname; /* true to force funcname inclusion */ bool show_funcname; /* true to force funcname inclusion */
bool hide_stmt; /* true to prevent STATEMENT: inclusion */ bool hide_stmt; /* true to prevent STATEMENT: inclusion */
bool hide_ctx; /* true to prevent CONTEXT: inclusion */
const char *filename; /* __FILE__ of ereport() call */ const char *filename; /* __FILE__ of ereport() call */
int lineno; /* __LINE__ of ereport() call */ int lineno; /* __LINE__ of ereport() call */
const char *funcname; /* __func__ of ereport() call */ const char *funcname; /* __func__ of ereport() call */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment