MCPcopy Create free account
hub / github.com/apache/cloudberry / write_csvlog

Function write_csvlog

src/backend/utils/error/elog.c:3393–3613  ·  view source on GitHub ↗

* Constructs the error message, depending on the Errordata it gets, in a CSV * format which is described in doc/src/sgml/config.sgml. */

Source from the content-addressed store, hash-verified

3391 * format which is described in doc/src/sgml/config.sgml.
3392 */
3393static void
3394write_csvlog(ErrorData *edata)
3395{
3396 StringInfoData buf;
3397 bool print_stmt = false;
3398
3399 /* static counter for line numbers */
3400 static long log_line_number = 0;
3401
3402 /* has counter been reset in current process? */
3403 static int log_my_pid = 0;
3404
3405 /*
3406 * This is one of the few places where we'd rather not inherit a static
3407 * variable's value from the postmaster. But since we will, reset it when
3408 * MyProcPid changes.
3409 */
3410 if (log_my_pid != MyProcPid)
3411 {
3412 log_line_number = 0;
3413 log_my_pid = MyProcPid;
3414 formatted_start_time[0] = '\0';
3415 }
3416 log_line_number++;
3417
3418 initStringInfo(&buf);
3419
3420 /*
3421 * timestamp with milliseconds
3422 *
3423 * Check if the timestamp is already calculated for the syslog message,
3424 * and use it if so. Otherwise, get the current timestamp. This is done
3425 * to put same timestamp in both syslog and csvlog messages.
3426 */
3427 if (formatted_log_time[0] == '\0')
3428 setup_formatted_log_time();
3429
3430 appendStringInfoString(&buf, formatted_log_time);
3431 appendStringInfoChar(&buf, ',');
3432
3433 /* username */
3434 if (MyProcPort)
3435 appendCSVLiteral(&buf, MyProcPort->user_name);
3436 appendStringInfoChar(&buf, ',');
3437
3438 /* database name */
3439 if (MyProcPort)
3440 appendCSVLiteral(&buf, MyProcPort->database_name);
3441 appendStringInfoChar(&buf, ',');
3442
3443 /* Process id */
3444 if (MyProcPid != 0)
3445 appendStringInfo(&buf, "%d", MyProcPid);
3446 appendStringInfoChar(&buf, ',');
3447
3448 /* Remote host and port */
3449 if (MyProcPort && MyProcPort->remote_host)
3450 {

Callers 1

Calls 15

initStringInfoFunction · 0.85
appendStringInfoStringFunction · 0.85
appendStringInfoCharFunction · 0.85
appendStringInfoFunction · 0.85
get_ps_displayFunction · 0.85
appendBinaryStringInfoFunction · 0.85
GetTopTransactionIdIfAnyFunction · 0.85
GetBackendTypeDescFunction · 0.85
pgstat_get_my_query_idFunction · 0.85
write_syslogger_fileFunction · 0.85
setup_formatted_log_timeFunction · 0.70
appendCSVLiteralFunction · 0.70

Tested by

no test coverage detected