Patch attached. Some kinds of emit log hooks might find it useful to
also compute the log_line_prefix.

Regards,
        Jeff Davis

From c3d4f14602c043918b8b6dab88a976dac1923208 Mon Sep 17 00:00:00 2001
From: Jeff Davis <j...@j-davis.com>
Date: Tue, 28 Jun 2022 11:39:33 -0700
Subject: [PATCH] Export log_line_prefix(); useful for emit_log_hook.

---
 src/backend/utils/error/elog.c | 3 +--
 src/include/utils/elog.h       | 3 +++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 55ee5423afb..4cd6a713ebb 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -176,7 +176,6 @@ static pg_noinline void set_backtrace(ErrorData *edata, int num_skip);
 static void set_errdata_field(MemoryContextData *cxt, char **ptr, const char *str);
 static void write_console(const char *line, int len);
 static const char *process_log_prefix_padding(const char *p, int *padding);
-static void log_line_prefix(StringInfo buf, ErrorData *edata);
 static void send_message_to_server_log(ErrorData *edata);
 static void send_message_to_frontend(ErrorData *edata);
 static void append_with_tabs(StringInfo buf, const char *str);
@@ -2441,7 +2440,7 @@ process_log_prefix_padding(const char *p, int *ppadding)
 /*
  * Format tag info for log lines; append to the provided buffer.
  */
-static void
+void
 log_line_prefix(StringInfo buf, ErrorData *edata)
 {
 	/* static counter for line numbers */
diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h
index f5c6cd904de..71aaf40614c 100644
--- a/src/include/utils/elog.h
+++ b/src/include/utils/elog.h
@@ -16,6 +16,8 @@
 
 #include <setjmp.h>
 
+#include "lib/stringinfo.h"
+
 /* Error level codes */
 #define DEBUG5		10			/* Debugging messages, in categories of
 								 * decreasing detail. */
@@ -439,6 +441,7 @@ extern PGDLLIMPORT bool syslog_split_messages;
 #define LOG_DESTINATION_JSONLOG	16
 
 /* Other exported functions */
+extern void log_line_prefix(StringInfo buf, ErrorData *edata);
 extern void DebugFileOpen(void);
 extern char *unpack_sql_state(int sql_state);
 extern bool in_error_recursion_trouble(void);
-- 
2.17.1

Reply via email to