42
42
*
43
43
*
44
44
* IDENTIFICATION
45
- * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.194 2007/08/19 01:41:25 adunstan Exp $
45
+ * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.195 2007/08/23 01:24:43 adunstan Exp $
46
46
*
47
47
*-------------------------------------------------------------------------
48
48
*/
@@ -133,7 +133,8 @@ static const char *error_severity(int elevel);
133
133
static void append_with_tabs (StringInfo buf , const char * str );
134
134
static bool is_log_level_output (int elevel , int log_min_level );
135
135
static void write_pipe_chunks (char * data , int len , int dest );
136
- static void get_error_message (StringInfo buf , ErrorData * edata );
136
+ static void get_csv_error_message (StringInfo buf , ErrorData * edata );
137
+ static void write_csvlog (ErrorData * edata );
137
138
138
139
/*
139
140
* errstart --- begin an error-reporting cycle
@@ -1809,9 +1810,7 @@ write_csvlog(ErrorData *edata)
1809
1810
appendStringInfoChar (& buf , ',' );
1810
1811
1811
1812
/* Error message and cursor position if any */
1812
- get_error_message (& msgbuf , edata );
1813
-
1814
- appendCSVLiteral (& buf , msgbuf .data );
1813
+ get_csv_error_message (& buf , edata );
1815
1814
1816
1815
appendStringInfoChar (& buf , '\n' );
1817
1816
@@ -1826,22 +1825,32 @@ write_csvlog(ErrorData *edata)
1826
1825
}
1827
1826
1828
1827
/*
1829
- * Appends the buffer with the error message and the cursor position.
1828
+ * Appends the buffer with the error message and the cursor position, all
1829
+ * CSV escaped.
1830
1830
*/
1831
1831
static void
1832
- get_error_message (StringInfo buf , ErrorData * edata )
1832
+ get_csv_error_message (StringInfo buf , ErrorData * edata )
1833
1833
{
1834
- if (edata -> message )
1835
- appendStringInfo (buf , "%s" , edata -> message );
1836
- else
1837
- appendStringInfo (buf , "%s" , _ ("missing error text" ));
1834
+ char * msg = edata -> message ? edata -> message : _ ("missing error text" );
1835
+ char c ;
1836
+
1837
+ appendStringInfoCharMacro (buf , '"' );
1838
+
1839
+ while ( (c = * msg ++ ) != '\0' )
1840
+ {
1841
+ if (c == '"' )
1842
+ appendStringInfoCharMacro (buf , '"' );
1843
+ appendStringInfoCharMacro (buf , c );
1844
+ }
1838
1845
1839
1846
if (edata -> cursorpos > 0 )
1840
1847
appendStringInfo (buf , _ (" at character %d" ),
1841
1848
edata -> cursorpos );
1842
1849
else if (edata -> internalpos > 0 )
1843
1850
appendStringInfo (buf , _ (" at character %d" ),
1844
1851
edata -> internalpos );
1852
+
1853
+ appendStringInfoCharMacro (buf , '"' );
1845
1854
}
1846
1855
1847
1856
/*
@@ -2032,13 +2041,19 @@ send_message_to_server_log(ErrorData *edata)
2032
2041
write (fileno (stderr ), buf .data , buf .len );
2033
2042
}
2034
2043
2044
+ /* If in the syslogger process, try to write messages direct to file */
2045
+ if (am_syslogger )
2046
+ write_syslogger_file (buf .data , buf .len , LOG_DESTINATION_STDERR );
2047
+
2048
+ /* Write to CSV log if enabled */
2035
2049
if (Log_destination & LOG_DESTINATION_CSVLOG )
2036
2050
{
2037
2051
if (redirection_done || am_syslogger )
2038
2052
{
2039
2053
/* send CSV data if it's safe to do so (syslogger doesn't need
2040
- * the pipe)
2054
+ * the pipe). First get back the space in the message buffer.
2041
2055
*/
2056
+ pfree (buf .data );
2042
2057
write_csvlog (edata );
2043
2058
}
2044
2059
else
@@ -2051,14 +2066,13 @@ send_message_to_server_log(ErrorData *edata)
2051
2066
/* write message to stderr unless we just sent it above */
2052
2067
write (fileno (stderr ), buf .data , buf .len );
2053
2068
}
2069
+ pfree (buf .data );
2054
2070
}
2055
2071
}
2056
-
2057
- /* If in the syslogger process, try to write messages direct to file */
2058
- if (am_syslogger )
2059
- write_syslogger_file (buf .data , buf .len , LOG_DESTINATION_STDERR );
2060
-
2061
- pfree (buf .data );
2072
+ else
2073
+ {
2074
+ pfree (buf .data );
2075
+ }
2062
2076
}
2063
2077
2064
2078
/*
0 commit comments