Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b40baa9

Browse files
committed
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
1 parent bf022d3 commit b40baa9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/backend/utils/error/elog.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -2438,10 +2438,19 @@ process_log_prefix_padding(const char *p, int *ppadding)
24382438
}
24392439

24402440
/*
2441-
* Format tag info for log lines; append to the provided buffer.
2441+
* Format log status information using Log_line_prefix.
24422442
*/
24432443
static void
24442444
log_line_prefix(StringInfo buf, ErrorData *edata)
2445+
{
2446+
log_status_format(buf, Log_line_prefix, edata);
2447+
}
2448+
2449+
/*
2450+
* Format log status info; append to the provided buffer.
2451+
*/
2452+
void
2453+
log_status_format(StringInfo buf, const char *format, ErrorData *edata)
24452454
{
24462455
/* static counter for line numbers */
24472456
static long log_line_number = 0;
@@ -2465,10 +2474,10 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
24652474
}
24662475
log_line_number++;
24672476

2468-
if (Log_line_prefix == NULL)
2477+
if (format == NULL)
24692478
return; /* in case guc hasn't run yet */
24702479

2471-
for (p = Log_line_prefix; *p != '\0'; p++)
2480+
for (p = format; *p != '\0'; p++)
24722481
{
24732482
if (*p != '%')
24742483
{

src/include/utils/elog.h

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <setjmp.h>
1818

19+
#include "lib/stringinfo.h"
20+
1921
/* Error level codes */
2022
#define DEBUG5 10 /* Debugging messages, in categories of
2123
* decreasing detail. */
@@ -439,6 +441,8 @@ extern PGDLLIMPORT bool syslog_split_messages;
439441
#define LOG_DESTINATION_JSONLOG 16
440442

441443
/* Other exported functions */
444+
extern void log_status_format(StringInfo buf, const char *format,
445+
ErrorData *edata);
442446
extern void DebugFileOpen(void);
443447
extern char *unpack_sql_state(int sql_state);
444448
extern bool in_error_recursion_trouble(void);

0 commit comments

Comments
 (0)