aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-06-30 16:47:02 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-06-30 16:47:02 +0000
commit219e29784dead71ed2c652057e131fe31ea7c354 (patch)
tree48d7c93579e6ba53eef4936d01e429b0618a11ec /src/backend/utils
parenta3cac5a3bf76f0e99e7f8663cd4eb6295bb347d8 (diff)
downloadpostgresql-219e29784dead71ed2c652057e131fe31ea7c354.tar.gz
postgresql-219e29784dead71ed2c652057e131fe31ea7c354.zip
Add GUC option log_error_verbosity to control which fields of error
reports get put into the postmaster log. Options are TERSE, DEFAULT, VERBOSE, with the same behavior as implemented on the client side in libpq.
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/error/elog.c70
-rw-r--r--src/backend/utils/misc/guc.c47
-rw-r--r--src/backend/utils/misc/postgresql.conf.sample9
3 files changed, 95 insertions, 31 deletions
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 9d371a5a26d..0660aaab9a9 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.111 2003/05/28 18:19:09 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.112 2003/06/30 16:47:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -68,6 +68,7 @@
ErrorContextCallback *error_context_stack = NULL;
/* GUC parameters */
+PGErrorVerbosity Log_error_verbosity = PGERROR_VERBOSE;
bool Log_timestamp; /* show timestamps in stderr output */
bool Log_pid; /* show PIDs in stderr output */
@@ -918,23 +919,52 @@ send_message_to_server_log(ErrorData *edata)
appendStringInfo(&buf, "%s: ", error_severity(edata->elevel));
+ if (Log_error_verbosity >= PGERROR_VERBOSE)
+ {
+ /* unpack MAKE_SQLSTATE code */
+ char tbuf[12];
+ int ssval;
+ int i;
+
+ ssval = edata->sqlerrcode;
+ for (i = 0; i < 5; i++)
+ {
+ tbuf[i] = PGUNSIXBIT(ssval);
+ ssval >>= 6;
+ }
+ tbuf[i] = '\0';
+ appendStringInfo(&buf, "%s: ", tbuf);
+ }
+
if (edata->message)
- appendStringInfo(&buf, "%s\n", edata->message);
+ appendStringInfoString(&buf, edata->message);
else
- appendStringInfoString(&buf, "missing error text\n");
+ appendStringInfoString(&buf, gettext("missing error text"));
- /* XXX showing of additional info should perhaps be optional */
- /* XXX ought to localize the label strings, probably */
+ if (edata->cursorpos > 0)
+ appendStringInfo(&buf, gettext(" at character %d"), edata->cursorpos);
- if (edata->detail)
- appendStringInfo(&buf, "DETAIL: %s\n", edata->detail);
- if (edata->hint)
- appendStringInfo(&buf, "HINT: %s\n", edata->hint);
- if (edata->context)
- appendStringInfo(&buf, "CONTEXT: %s\n", edata->context);
- if (edata->funcname && edata->filename)
- appendStringInfo(&buf, "IN: %s (%s:%d)\n",
- edata->funcname, edata->filename, edata->lineno);
+ appendStringInfoChar(&buf, '\n');
+
+ if (Log_error_verbosity >= PGERROR_DEFAULT)
+ {
+ if (edata->detail)
+ appendStringInfo(&buf, gettext("DETAIL: %s\n"), edata->detail);
+ if (edata->hint)
+ appendStringInfo(&buf, gettext("HINT: %s\n"), edata->hint);
+ if (edata->context)
+ appendStringInfo(&buf, gettext("CONTEXT: %s\n"), edata->context);
+ if (Log_error_verbosity >= PGERROR_VERBOSE)
+ {
+ if (edata->funcname && edata->filename)
+ appendStringInfo(&buf, gettext("LOCATION: %s, %s:%d\n"),
+ edata->funcname, edata->filename,
+ edata->lineno);
+ else if (edata->filename)
+ appendStringInfo(&buf, gettext("LOCATION: %s:%d\n"),
+ edata->filename, edata->lineno);
+ }
+ }
/*
* If the user wants the query that generated this error logged, do so.
@@ -942,7 +972,8 @@ send_message_to_server_log(ErrorData *edata)
* for queries triggered by extended query protocol; how to improve?
*/
if (edata->elevel >= log_min_error_statement && debug_query_string != NULL)
- appendStringInfo(&buf, "STATEMENT: %s\n", debug_query_string);
+ appendStringInfo(&buf, gettext("STATEMENT: %s\n"),
+ debug_query_string);
#ifdef HAVE_SYSLOG
@@ -992,11 +1023,10 @@ send_message_to_server_log(ErrorData *edata)
* Timestamp and PID are only used for stderr output --- we assume
* the syslog daemon will supply them for us in the other case.
*/
- if (Log_timestamp)
- fprintf(stderr, "%s", print_timestamp());
- if (Log_pid)
- fprintf(stderr, "%s", print_pid());
- fprintf(stderr, "%s", buf.data);
+ fprintf(stderr, "%s%s%s",
+ Log_timestamp ? print_timestamp() : "",
+ Log_pid ? print_pid() : "",
+ buf.data);
}
pfree(buf.data);
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index dfdc4f82e7f..6e0da5bbaab 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.132 2003/06/27 19:08:38 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.133 2003/06/30 16:47:01 tgl Exp $
*
*--------------------------------------------------------------------
*/
@@ -94,6 +94,8 @@ static const char *assign_min_error_statement(const char *newval, bool doit,
bool interactive);
static const char *assign_msglvl(int *var, const char *newval,
bool doit, bool interactive);
+static const char *assign_log_error_verbosity(const char *newval, bool doit,
+ bool interactive);
static bool assign_phony_autocommit(bool newval, bool doit, bool interactive);
@@ -134,9 +136,10 @@ int client_min_messages = NOTICE;
* cases provide the value for SHOW to display. The real state is elsewhere
* and is kept in sync by assign_hooks.
*/
-static char *log_min_error_statement_str;
-static char *log_min_messages_str;
static char *client_min_messages_str;
+static char *log_min_messages_str;
+static char *log_error_verbosity_str;
+static char *log_min_error_statement_str;
static bool phony_autocommit;
static bool session_auth_is_superuser;
static double phony_random_seed;
@@ -821,6 +824,16 @@ static struct config_string
},
{
+ {"log_min_messages", PGC_SUSET}, &log_min_messages_str,
+ "notice", assign_log_min_messages, NULL
+ },
+
+ {
+ {"log_error_verbosity", PGC_SUSET}, &log_error_verbosity_str,
+ "default", assign_log_error_verbosity, NULL
+ },
+
+ {
{"log_min_error_statement", PGC_SUSET}, &log_min_error_statement_str,
"panic", assign_min_error_statement, NULL
},
@@ -909,11 +922,6 @@ static struct config_string
PG_VERSION, NULL, NULL
},
- {
- {"log_min_messages", PGC_SUSET}, &log_min_messages_str,
- "notice", assign_log_min_messages, NULL
- },
-
/* Not for general use --- used by SET SESSION AUTHORIZATION */
{
{"session_authorization", PGC_USERSET, GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL},
@@ -3468,6 +3476,29 @@ assign_msglvl(int *var, const char *newval, bool doit, bool interactive)
return newval; /* OK */
}
+static const char *
+assign_log_error_verbosity(const char *newval, bool doit, bool interactive)
+{
+ if (strcasecmp(newval, "terse") == 0)
+ {
+ if (doit)
+ Log_error_verbosity = PGERROR_TERSE;
+ }
+ else if (strcasecmp(newval, "default") == 0)
+ {
+ if (doit)
+ Log_error_verbosity = PGERROR_DEFAULT;
+ }
+ else if (strcasecmp(newval, "verbose") == 0)
+ {
+ if (doit)
+ Log_error_verbosity = PGERROR_VERBOSE;
+ }
+ else
+ return NULL; /* fail */
+ return newval; /* OK */
+}
+
static bool
assign_phony_autocommit(bool newval, bool doit, bool interactive)
{
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 594c230a769..57c6e55cb22 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -119,13 +119,16 @@
#
# Message display
#
+#client_min_messages = notice # Values, in order of decreasing detail:
+ # debug5, debug4, debug3, debug2, debug1,
+ # log, info, notice, warning, error
#log_min_messages = notice # Values, in order of decreasing detail:
# debug5, debug4, debug3, debug2, debug1,
# info, notice, warning, error, log, fatal,
# panic
-#client_min_messages = notice # Values, in order of decreasing detail:
- # debug5, debug4, debug3, debug2, debug1,
- # log, info, notice, warning, error
+
+#log_error_verbosity = default # terse, default, or verbose messages
+
#silent_mode = false
#log_connections = false