Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bbba508

Browse files
committed
Fix elog tab-insertion code to insert tabs only where wanted.
1 parent 1b7ac7f commit bbba508

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

src/backend/utils/error/elog.c

+38-30
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.124 2003/10/08 03:49:38 momjian Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.125 2003/10/17 16:49:03 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -145,7 +145,7 @@ static const char *useful_strerror(int errnum);
145145
static const char *error_severity(int elevel);
146146
static const char *print_timestamp(void);
147147
static const char *print_pid(void);
148-
static char *str_prepend_tabs(const char *str);
148+
static void append_with_tabs(StringInfo buf, const char *str);
149149

150150

151151
/*
@@ -1053,9 +1053,9 @@ send_message_to_server_log(ErrorData *edata)
10531053
}
10541054

10551055
if (edata->message)
1056-
appendStringInfoString(&buf, edata->message);
1056+
append_with_tabs(&buf, edata->message);
10571057
else
1058-
appendStringInfoString(&buf, gettext("missing error text"));
1058+
append_with_tabs(&buf, gettext("missing error text"));
10591059

10601060
if (edata->cursorpos > 0)
10611061
appendStringInfo(&buf, gettext(" at character %d"), edata->cursorpos);
@@ -1065,13 +1065,26 @@ send_message_to_server_log(ErrorData *edata)
10651065
if (Log_error_verbosity >= PGERROR_DEFAULT)
10661066
{
10671067
if (edata->detail)
1068-
appendStringInfo(&buf, gettext("DETAIL: %s\n"), edata->detail);
1068+
{
1069+
appendStringInfoString(&buf, gettext("DETAIL: "));
1070+
append_with_tabs(&buf, edata->detail);
1071+
appendStringInfoChar(&buf, '\n');
1072+
}
10691073
if (edata->hint)
1070-
appendStringInfo(&buf, gettext("HINT: %s\n"), edata->hint);
1074+
{
1075+
appendStringInfoString(&buf, gettext("HINT: "));
1076+
append_with_tabs(&buf, edata->hint);
1077+
appendStringInfoChar(&buf, '\n');
1078+
}
10711079
if (edata->context)
1072-
appendStringInfo(&buf, gettext("CONTEXT: %s\n"), edata->context);
1080+
{
1081+
appendStringInfoString(&buf, gettext("CONTEXT: "));
1082+
append_with_tabs(&buf, edata->context);
1083+
appendStringInfoChar(&buf, '\n');
1084+
}
10731085
if (Log_error_verbosity >= PGERROR_VERBOSE)
10741086
{
1087+
/* assume no newlines in funcname or filename... */
10751088
if (edata->funcname && edata->filename)
10761089
appendStringInfo(&buf, gettext("LOCATION: %s, %s:%d\n"),
10771090
edata->funcname, edata->filename,
@@ -1083,14 +1096,14 @@ send_message_to_server_log(ErrorData *edata)
10831096
}
10841097

10851098
/*
1086-
* If the user wants the query that generated this error logged, do
1087-
* so. We use debug_query_string to get at the query, which is kinda
1088-
* useless for queries triggered by extended query protocol; how to
1089-
* improve?
1099+
* If the user wants the query that generated this error logged, do it.
10901100
*/
10911101
if (edata->elevel >= log_min_error_statement && debug_query_string != NULL)
1092-
appendStringInfo(&buf, gettext("STATEMENT: %s\n"),
1093-
debug_query_string);
1102+
{
1103+
appendStringInfoString(&buf, gettext("STATEMENT: "));
1104+
append_with_tabs(&buf, debug_query_string);
1105+
appendStringInfoChar(&buf, '\n');
1106+
}
10941107

10951108

10961109
#ifdef HAVE_SYSLOG
@@ -1136,17 +1149,14 @@ send_message_to_server_log(ErrorData *edata)
11361149
/* Write to stderr, if enabled */
11371150
if (Use_syslog <= 1 || whereToSendOutput == Debug)
11381151
{
1139-
char *p = str_prepend_tabs(buf.data);
1140-
11411152
/*
11421153
* Timestamp and PID are only used for stderr output --- we assume
11431154
* the syslog daemon will supply them for us in the other case.
11441155
*/
11451156
fprintf(stderr, "%s%s%s",
11461157
Log_timestamp ? print_timestamp() : "",
11471158
Log_pid ? print_pid() : "",
1148-
p);
1149-
pfree(p);
1159+
buf.data);
11501160
}
11511161

11521162
pfree(buf.data);
@@ -1252,7 +1262,7 @@ send_message_to_frontend(ErrorData *edata)
12521262
appendStringInfo(&buf, "%s: ", edata->funcname);
12531263

12541264
if (edata->message)
1255-
appendStringInfo(&buf, "%s", edata->message);
1265+
appendStringInfoString(&buf, edata->message);
12561266
else
12571267
appendStringInfoString(&buf, gettext("missing error text"));
12581268

@@ -1456,22 +1466,20 @@ print_pid(void)
14561466
}
14571467

14581468
/*
1459-
* str_prepend_tabs
1469+
* append_with_tabs
14601470
*
1461-
* This string prepends a tab to message continuation lines.
1471+
* Append the string to the StringInfo buffer, inserting a tab after any
1472+
* newline.
14621473
*/
1463-
static char *str_prepend_tabs(const char *str)
1474+
static void
1475+
append_with_tabs(StringInfo buf, const char *str)
14641476
{
1465-
char *outstr = palloc(strlen(str) * 2 + 1);
1466-
int len = strlen(str);
1467-
int i, outlen = 0;
1477+
char ch;
14681478

1469-
for (i = 0; i < len; i++)
1479+
while ((ch = *str++) != '\0')
14701480
{
1471-
outstr[outlen++] = str[i];
1472-
if (str[i] == '\n' && str[i+1] != '\0' )
1473-
outstr[outlen++] = '\t';
1481+
appendStringInfoCharMacro(buf, ch);
1482+
if (ch == '\n')
1483+
appendStringInfoCharMacro(buf, '\t');
14741484
}
1475-
outstr[outlen++] = '\0';
1476-
return outstr;
14771485
}

0 commit comments

Comments
 (0)