* 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
| 1736 | * even though its stderr does not point at the syslog pipe. |
| 1737 | */ |
| 1738 | void 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 | * |
no test coverage detected