37
37
*
38
38
*
39
39
* 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 $
41
41
*
42
42
*-------------------------------------------------------------------------
43
43
*/
@@ -145,7 +145,7 @@ static const char *useful_strerror(int errnum);
145
145
static const char * error_severity (int elevel );
146
146
static const char * print_timestamp (void );
147
147
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 );
149
149
150
150
151
151
/*
@@ -1053,9 +1053,9 @@ send_message_to_server_log(ErrorData *edata)
1053
1053
}
1054
1054
1055
1055
if (edata -> message )
1056
- appendStringInfoString (& buf , edata -> message );
1056
+ append_with_tabs (& buf , edata -> message );
1057
1057
else
1058
- appendStringInfoString (& buf , gettext ("missing error text" ));
1058
+ append_with_tabs (& buf , gettext ("missing error text" ));
1059
1059
1060
1060
if (edata -> cursorpos > 0 )
1061
1061
appendStringInfo (& buf , gettext (" at character %d" ), edata -> cursorpos );
@@ -1065,13 +1065,26 @@ send_message_to_server_log(ErrorData *edata)
1065
1065
if (Log_error_verbosity >= PGERROR_DEFAULT )
1066
1066
{
1067
1067
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
+ }
1069
1073
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
+ }
1071
1079
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
+ }
1073
1085
if (Log_error_verbosity >= PGERROR_VERBOSE )
1074
1086
{
1087
+ /* assume no newlines in funcname or filename... */
1075
1088
if (edata -> funcname && edata -> filename )
1076
1089
appendStringInfo (& buf , gettext ("LOCATION: %s, %s:%d\n" ),
1077
1090
edata -> funcname , edata -> filename ,
@@ -1083,14 +1096,14 @@ send_message_to_server_log(ErrorData *edata)
1083
1096
}
1084
1097
1085
1098
/*
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.
1090
1100
*/
1091
1101
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
+ }
1094
1107
1095
1108
1096
1109
#ifdef HAVE_SYSLOG
@@ -1136,17 +1149,14 @@ send_message_to_server_log(ErrorData *edata)
1136
1149
/* Write to stderr, if enabled */
1137
1150
if (Use_syslog <= 1 || whereToSendOutput == Debug )
1138
1151
{
1139
- char * p = str_prepend_tabs (buf .data );
1140
-
1141
1152
/*
1142
1153
* Timestamp and PID are only used for stderr output --- we assume
1143
1154
* the syslog daemon will supply them for us in the other case.
1144
1155
*/
1145
1156
fprintf (stderr , "%s%s%s" ,
1146
1157
Log_timestamp ? print_timestamp () : "" ,
1147
1158
Log_pid ? print_pid () : "" ,
1148
- p );
1149
- pfree (p );
1159
+ buf .data );
1150
1160
}
1151
1161
1152
1162
pfree (buf .data );
@@ -1252,7 +1262,7 @@ send_message_to_frontend(ErrorData *edata)
1252
1262
appendStringInfo (& buf , "%s: " , edata -> funcname );
1253
1263
1254
1264
if (edata -> message )
1255
- appendStringInfo (& buf , "%s" , edata -> message );
1265
+ appendStringInfoString (& buf , edata -> message );
1256
1266
else
1257
1267
appendStringInfoString (& buf , gettext ("missing error text" ));
1258
1268
@@ -1456,22 +1466,20 @@ print_pid(void)
1456
1466
}
1457
1467
1458
1468
/*
1459
- * str_prepend_tabs
1469
+ * append_with_tabs
1460
1470
*
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.
1462
1473
*/
1463
- static char * str_prepend_tabs (const char * str )
1474
+ static void
1475
+ append_with_tabs (StringInfo buf , const char * str )
1464
1476
{
1465
- char * outstr = palloc (strlen (str ) * 2 + 1 );
1466
- int len = strlen (str );
1467
- int i , outlen = 0 ;
1477
+ char ch ;
1468
1478
1469
- for ( i = 0 ; i < len ; i ++ )
1479
+ while (( ch = * str ++ ) != '\0' )
1470
1480
{
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' ) ;
1474
1484
}
1475
- outstr [outlen ++ ] = '\0' ;
1476
- return outstr ;
1477
1485
}
0 commit comments