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

Function write_syslogger_file_binary

src/backend/postmaster/syslogger.c:1738–1766  ·  view source on GitHub ↗

* Write binary data to the currently open logfile * * On Windows the data arriving in the pipe already has CR/LF newlines, * so we must send it to the file without further translation. * * This is exported so that elog.c can call it when MyBackendType is B_LOGGER. * This allows the syslogger process to record elog messages of its own, * even though its stderr does not point at the syslog pi

Source from the content-addressed store, hash-verified

1736 * even though its stderr does not point at the syslog pipe.
1737 */
1738void write_syslogger_file_binary(const char *buffer, int count, int destination)
1739{
1740 FILE *logfile;
1741
1742 /*
1743 * If we're told to write to csvlogFile, but it's not open, dump the data
1744 * to syslogFile (which is always open) instead. This can happen if CSV
1745 * output is enabled after postmaster start and we've been unable to open
1746 * csvlogFile. There are also race conditions during a parameter change
1747 * whereby backends might send us CSV output before we open csvlogFile or
1748 * after we close it. Writing CSV-formatted output to the regular log
1749 * file isn't great, but it beats dropping log output on the floor.
1750 *
1751 * Think not to improve this by trying to open csvlogFile on-the-fly. Any
1752 * failure in that would lead to recursion.
1753 *
1754 * The following logic is a little different from GP7.
1755 * We follow the upstream pattern. Use ternary operator to set the `logfile`
1756 * variable to csvlogFile or syslogFile in different situations.
1757 * Thus we can write to it directly without if-else sentences.
1758 * We need to ensure that everytime we call write_syslogger_file_binary, the
1759 * destination should always be LOG_DESTINATION_CSVLOG
1760 * or LOG_DESTINATION_STDERR.
1761 */
1762 logfile = (destination == LOG_DESTINATION_CSVLOG &&
1763 csvlogFile != NULL) ? csvlogFile : syslogFile;
1764
1765 write_binary_to_file(buffer, count, logfile);
1766}
1767/*
1768 * Write text to the currently open logfile
1769 *

Callers 12

append_stacktraceFunction · 0.85
write_syslogger_in_csvFunction · 0.85
syslogger_write_strFunction · 0.85
syslogger_write_int32Function · 0.85
syslogger_write_str_endFunction · 0.85
syslogger_log_chunk_dataFunction · 0.85
write_syslogger_fileFunction · 0.85

Calls 1

write_binary_to_fileFunction · 0.85

Tested by

no test coverage detected