diff options
author | Jeff Davis | 2022-07-11 19:29:33 +0000 |
---|---|---|
committer | Jeff Davis | 2022-07-11 19:29:33 +0000 |
commit | b40baa96a7ad789718dcf59b1dd73bae15c3a7e1 (patch) | |
tree | e4c0e7db63eea5c1a1d12c275b2566d8b3353b6e | |
parent | bf022d337ef096c79e6a0b51f0b42e69749ae210 (diff) |
Provide log_status_format(), useful for an emit_log_hook.
Refactor so that log_line_prefix() is a thin wrapper over a new
function log_status_format(), and move the implementation to the
latter. Export log_status_format() so that it can be used by an
emit_log_hook.
Discussion: https://postgr.es/m/39c8197652f4d3050aedafae79fa5af31096505f.camel%40j-davis.com
Reviewed-by: Michael Paquier, Alvaro Herrera
-rw-r--r-- | src/backend/utils/error/elog.c | 15 | ||||
-rw-r--r-- | src/include/utils/elog.h | 4 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 59124bd9cc..95f32de4e2 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -2438,11 +2438,20 @@ process_log_prefix_padding(const char *p, int *ppadding) } /* - * Format tag info for log lines; append to the provided buffer. + * Format log status information using Log_line_prefix. */ static void log_line_prefix(StringInfo buf, ErrorData *edata) { + log_status_format(buf, Log_line_prefix, edata); +} + +/* + * Format log status info; append to the provided buffer. + */ +void +log_status_format(StringInfo buf, const char *format, ErrorData *edata) +{ /* static counter for line numbers */ static long log_line_number = 0; @@ -2465,10 +2474,10 @@ log_line_prefix(StringInfo buf, ErrorData *edata) } log_line_number++; - if (Log_line_prefix == NULL) + if (format == NULL) return; /* in case guc hasn't run yet */ - for (p = Log_line_prefix; *p != '\0'; p++) + for (p = format; *p != '\0'; p++) { if (*p != '%') { diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index f5c6cd904d..68ead8e873 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,8 @@ extern PGDLLIMPORT bool syslog_split_messages; #define LOG_DESTINATION_JSONLOG 16 /* Other exported functions */ +extern void log_status_format(StringInfo buf, const char *format, + ErrorData *edata); extern void DebugFileOpen(void); extern char *unpack_sql_state(int sql_state); extern bool in_error_recursion_trouble(void); |