*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.194 2007/08/19 01:41:25 adunstan Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.195 2007/08/23 01:24:43 adunstan Exp $
*
*-------------------------------------------------------------------------
*/
static void append_with_tabs(StringInfo buf, const char *str);
static bool is_log_level_output(int elevel, int log_min_level);
static void write_pipe_chunks(char *data, int len, int dest);
-static void get_error_message(StringInfo buf, ErrorData *edata);
+static void get_csv_error_message(StringInfo buf, ErrorData *edata);
+static void write_csvlog(ErrorData *edata);
/*
* errstart --- begin an error-reporting cycle
appendStringInfoChar(&buf, ',');
/* Error message and cursor position if any */
- get_error_message(&msgbuf, edata);
-
- appendCSVLiteral(&buf, msgbuf.data);
+ get_csv_error_message(&buf, edata);
appendStringInfoChar(&buf, '\n');
}
/*
- * Appends the buffer with the error message and the cursor position.
+ * Appends the buffer with the error message and the cursor position, all
+ * CSV escaped.
*/
static void
-get_error_message(StringInfo buf, ErrorData *edata)
+get_csv_error_message(StringInfo buf, ErrorData *edata)
{
- if (edata->message)
- appendStringInfo(buf, "%s", edata->message);
- else
- appendStringInfo(buf, "%s", _("missing error text"));
+ char *msg = edata->message ? edata-> message : _("missing error text");
+ char c;
+
+ appendStringInfoCharMacro(buf, '"');
+
+ while ( (c = *msg++) != '\0' )
+ {
+ if (c == '"')
+ appendStringInfoCharMacro(buf, '"');
+ appendStringInfoCharMacro(buf, c);
+ }
if (edata->cursorpos > 0)
appendStringInfo(buf, _(" at character %d"),
else if (edata->internalpos > 0)
appendStringInfo(buf, _(" at character %d"),
edata->internalpos);
+
+ appendStringInfoCharMacro(buf, '"');
}
/*
write(fileno(stderr), buf.data, buf.len);
}
+ /* If in the syslogger process, try to write messages direct to file */
+ if (am_syslogger)
+ write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_STDERR);
+
+ /* Write to CSV log if enabled */
if (Log_destination & LOG_DESTINATION_CSVLOG)
{
if (redirection_done || am_syslogger)
{
/* send CSV data if it's safe to do so (syslogger doesn't need
- * the pipe)
+ * the pipe). First get back the space in the message buffer.
*/
+ pfree(buf.data);
write_csvlog(edata);
}
else
/* write message to stderr unless we just sent it above */
write(fileno(stderr), buf.data, buf.len);
}
+ pfree(buf.data);
}
}
-
- /* If in the syslogger process, try to write messages direct to file */
- if (am_syslogger)
- write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_STDERR);
-
- pfree(buf.data);
+ else
+ {
+ pfree(buf.data);
+ }
}
/*