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

Function write_console

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

Source from the content-addressed store, hash-verified

2760
2761
2762static void
2763write_console(const char *line, int len)
2764{
2765 int rc;
2766
2767#ifdef WIN32
2768
2769 /*
2770 * Try to convert the message to UTF16 and write it with WriteConsoleW().
2771 * Fall back on write() if anything fails.
2772 *
2773 * In contrast to write_eventlog(), don't skip straight to write() based
2774 * on the applicable encodings. Unlike WriteConsoleW(), write() depends
2775 * on the suitability of the console output code page. Since we put
2776 * stderr into binary mode in SubPostmasterMain(), write() skips the
2777 * necessary translation anyway.
2778 *
2779 * WriteConsoleW() will fail if stderr is redirected, so just fall through
2780 * to writing unconverted to the logfile in this case.
2781 *
2782 * Since we palloc the structure required for conversion, also fall
2783 * through to writing unconverted if we have not yet set up
2784 * CurrentMemoryContext.
2785 */
2786 if (!in_error_recursion_trouble() &&
2787 !redirection_done &&
2788 CurrentMemoryContext != NULL)
2789 {
2790 WCHAR *utf16;
2791 int utf16len;
2792
2793 utf16 = pgwin32_message_to_UTF16(line, len, &utf16len);
2794 if (utf16 != NULL)
2795 {
2796 HANDLE stdHandle;
2797 DWORD written;
2798
2799 stdHandle = GetStdHandle(STD_ERROR_HANDLE);
2800 if (WriteConsoleW(stdHandle, utf16, utf16len, &written, NULL))
2801 {
2802 pfree(utf16);
2803 return;
2804 }
2805
2806 /*
2807 * In case WriteConsoleW() failed, fall back to writing the
2808 * message unconverted.
2809 */
2810 pfree(utf16);
2811 }
2812 }
2813#else
2814
2815 /*
2816 * Conversion on non-win32 platforms is not implemented yet. It requires
2817 * non-throw version of pg_do_encoding_conversion(), that converts
2818 * unconvertable characters to '?' without errors.
2819 *

Callers 2

write_stderrFunction · 0.70

Calls 3

pgwin32_message_to_UTF16Function · 0.85
pfreeFunction · 0.50

Tested by

no test coverage detected