4242 *
4343 *
4444 * IDENTIFICATION
45- * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.216 2009/06/25 23:07:15 tgl Exp $
45+ * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.217 2009/07/03 19:14:25 petere Exp $
4646 *
4747 *-------------------------------------------------------------------------
4848 */
@@ -144,7 +144,7 @@ static char formatted_log_time[FORMATTED_TS_LEN];
144144} while (0)
145145
146146
147- static void log_line_prefix (StringInfo buf );
147+ static void log_line_prefix (StringInfo buf , ErrorData * edata );
148148static void send_message_to_server_log (ErrorData * edata );
149149static void send_message_to_frontend (ErrorData * edata );
150150static char * expand_fmt_string (const char * fmt ,ErrorData * edata );
@@ -1677,7 +1677,7 @@ setup_formatted_start_time(void)
16771677 * Format tag info for log lines; append to the provided buffer.
16781678 */
16791679static void
1680- log_line_prefix (StringInfo buf )
1680+ log_line_prefix (StringInfo buf , ErrorData * edata )
16811681{
16821682/* static counter for line numbers */
16831683static long log_line_number = 0 ;
@@ -1814,6 +1814,9 @@ log_line_prefix(StringInfo buf)
18141814case 'x' :
18151815appendStringInfo (buf ,"%u" ,GetTopTransactionIdIfAny ());
18161816break ;
1817+ case 'e' :
1818+ appendStringInfoString (buf ,unpack_sql_state (edata -> sqlerrcode ));
1819+ break ;
18171820case '%' :
18181821appendStringInfoChar (buf ,'%' );
18191822break ;
@@ -2070,7 +2073,7 @@ send_message_to_server_log(ErrorData *edata)
20702073
20712074formatted_log_time [0 ]= '\0' ;
20722075
2073- log_line_prefix (& buf );
2076+ log_line_prefix (& buf , edata );
20742077appendStringInfo (& buf ,"%s: " ,error_severity (edata -> elevel ));
20752078
20762079if (Log_error_verbosity >=PGERROR_VERBOSE )
@@ -2094,35 +2097,35 @@ send_message_to_server_log(ErrorData *edata)
20942097{
20952098if (edata -> detail_log )
20962099{
2097- log_line_prefix (& buf );
2100+ log_line_prefix (& buf , edata );
20982101appendStringInfoString (& buf ,_ ("DETAIL: " ));
20992102append_with_tabs (& buf ,edata -> detail_log );
21002103appendStringInfoChar (& buf ,'\n' );
21012104}
21022105else if (edata -> detail )
21032106{
2104- log_line_prefix (& buf );
2107+ log_line_prefix (& buf , edata );
21052108appendStringInfoString (& buf ,_ ("DETAIL: " ));
21062109append_with_tabs (& buf ,edata -> detail );
21072110appendStringInfoChar (& buf ,'\n' );
21082111}
21092112if (edata -> hint )
21102113{
2111- log_line_prefix (& buf );
2114+ log_line_prefix (& buf , edata );
21122115appendStringInfoString (& buf ,_ ("HINT: " ));
21132116append_with_tabs (& buf ,edata -> hint );
21142117appendStringInfoChar (& buf ,'\n' );
21152118}
21162119if (edata -> internalquery )
21172120{
2118- log_line_prefix (& buf );
2121+ log_line_prefix (& buf , edata );
21192122appendStringInfoString (& buf ,_ ("QUERY: " ));
21202123append_with_tabs (& buf ,edata -> internalquery );
21212124appendStringInfoChar (& buf ,'\n' );
21222125}
21232126if (edata -> context )
21242127{
2125- log_line_prefix (& buf );
2128+ log_line_prefix (& buf , edata );
21262129appendStringInfoString (& buf ,_ ("CONTEXT: " ));
21272130append_with_tabs (& buf ,edata -> context );
21282131appendStringInfoChar (& buf ,'\n' );
@@ -2132,14 +2135,14 @@ send_message_to_server_log(ErrorData *edata)
21322135/* assume no newlines in funcname or filename... */
21332136if (edata -> funcname && edata -> filename )
21342137{
2135- log_line_prefix (& buf );
2138+ log_line_prefix (& buf , edata );
21362139appendStringInfo (& buf ,_ ("LOCATION: %s, %s:%d\n" ),
21372140edata -> funcname ,edata -> filename ,
21382141edata -> lineno );
21392142}
21402143else if (edata -> filename )
21412144{
2142- log_line_prefix (& buf );
2145+ log_line_prefix (& buf , edata );
21432146appendStringInfo (& buf ,_ ("LOCATION: %s:%d\n" ),
21442147edata -> filename ,edata -> lineno );
21452148}
@@ -2153,7 +2156,7 @@ send_message_to_server_log(ErrorData *edata)
21532156debug_query_string != NULL &&
21542157!edata -> hide_stmt )
21552158{
2156- log_line_prefix (& buf );
2159+ log_line_prefix (& buf , edata );
21572160appendStringInfoString (& buf ,_ ("STATEMENT: " ));
21582161append_with_tabs (& buf ,debug_query_string );
21592162appendStringInfoChar (& buf ,'\n' );