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

Function write_eventlog

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

* Write a message line to the windows event log */

Source from the content-addressed store, hash-verified

2577 * Write a message line to the windows event log
2578 */
2579static void
2580write_eventlog(int level, const char *line, int len)
2581{
2582 WCHAR *utf16;
2583 int eventlevel = EVENTLOG_ERROR_TYPE;
2584 static HANDLE evtHandle = INVALID_HANDLE_VALUE;
2585
2586 if (evtHandle == INVALID_HANDLE_VALUE)
2587 {
2588 evtHandle = RegisterEventSource(NULL,
2589 event_source ? event_source : DEFAULT_EVENT_SOURCE);
2590 if (evtHandle == NULL)
2591 {
2592 evtHandle = INVALID_HANDLE_VALUE;
2593 return;
2594 }
2595 }
2596
2597 switch (level)
2598 {
2599 case DEBUG5:
2600 case DEBUG4:
2601 case DEBUG3:
2602 case DEBUG2:
2603 case DEBUG1:
2604 case LOG:
2605 case LOG_SERVER_ONLY:
2606 case INFO:
2607 case NOTICE:
2608 eventlevel = EVENTLOG_INFORMATION_TYPE;
2609 break;
2610 case WARNING:
2611 case WARNING_CLIENT_ONLY:
2612 eventlevel = EVENTLOG_WARNING_TYPE;
2613 break;
2614 case ERROR:
2615 case FATAL:
2616 case PANIC:
2617 default:
2618 eventlevel = EVENTLOG_ERROR_TYPE;
2619 break;
2620 }
2621
2622 /*
2623 * If message character encoding matches the encoding expected by
2624 * ReportEventA(), call it to avoid the hazards of conversion. Otherwise,
2625 * try to convert the message to UTF16 and write it with ReportEventW().
2626 * Fall back on ReportEventA() if conversion failed.
2627 *
2628 * Since we palloc the structure required for conversion, also fall
2629 * through to writing unconverted if we have not yet set up
2630 * CurrentMemoryContext.
2631 *
2632 * Also verify that we are not on our way into error recursion trouble due
2633 * to error messages thrown deep inside pgwin32_message_to_UTF16().
2634 */
2635 if (!in_error_recursion_trouble() &&
2636 CurrentMemoryContext != NULL &&

Callers 2

write_stderrFunction · 0.70

Calls 5

GetMessageEncodingFunction · 0.85
pgwin32_message_to_UTF16Function · 0.85
GetACPEncodingFunction · 0.70
pfreeFunction · 0.50

Tested by

no test coverage detected