pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Export log_line_prefix(); useful for emit_log_hook.
6+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2022-07-11 b40baa96a7  Provide log_status_format(), useful for an emit_log_hook.
* Export log_line_prefix(); useful for emit_log_hook.
@ 2022-06-28 18:52 Jeff Davis <pgsql@j-davis.com>
  2022-06-29 01:17 ` Re: Export log_line_prefix(); useful for emit_log_hook. Michael Paquier <michael@paquier.xyz>
  2022-06-29 13:09 ` Re: Export log_line_prefix(); useful for emit_log_hook. Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 2 replies; 6+ messages in thread

From: Jeff Davis @ 2022-06-28 18:52 UTC (permalink / raw)
  To: pgsql-hackers

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

Regards,
	Jeff Davis

Attachments:

0001-Export-log_line_prefix-useful-for-emit_log_hook.patch (text/x-patch, 2.0K) download From c3d4f14602c043918b8b6dab88a976dac1923208 Mon Sep 17 00:00:00 2001 From: Jeff Davis <jeff@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
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: Export log_line_prefix(); useful for emit_log_hook.
  2022-06-28 18:52 Export log_line_prefix(); useful for emit_log_hook. Jeff Davis <pgsql@j-davis.com>
@ 2022-06-29 01:17 ` Michael Paquier <michael@paquier.xyz>
  2022-06-29 05:32   ` Re: Export log_line_prefix(); useful for emit_log_hook. Jeff Davis <pgsql@j-davis.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Michael Paquier @ 2022-06-29 01:17 UTC (permalink / raw)
  To: Jeff Davis <pgsql@j-davis.com>; +Cc: pgsql-hackers

On Tue, Jun 28, 2022 at 11:52:56AM -0700, Jeff Davis wrote:
> Patch attached. Some kinds of emit log hooks might find it useful to
> also compute the log_line_prefix.

Have you played with anything specific that would require that?  I
am fine to expose this routine, being mostly curious about what kind
of recent format implemented with the elog hook would use it.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Export log_line_prefix(); useful for emit_log_hook.
  2022-06-28 18:52 Export log_line_prefix(); useful for emit_log_hook. Jeff Davis <pgsql@j-davis.com>
  2022-06-29 01:17 ` Re: Export log_line_prefix(); useful for emit_log_hook. Michael Paquier <michael@paquier.xyz>
@ 2022-06-29 05:32   ` Jeff Davis <pgsql@j-davis.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Jeff Davis @ 2022-06-29 05:32 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: pgsql-hackers

On Wed, 2022-06-29 at 10:17 +0900, Michael Paquier wrote:
> On Tue, Jun 28, 2022 at 11:52:56AM -0700, Jeff Davis wrote:
> > Patch attached. Some kinds of emit log hooks might find it useful
> > to
> > also compute the log_line_prefix.
> 
> Have you played with anything specific that would require that?  I
> am fine to expose this routine, being mostly curious about what kind
> of recent format implemented with the elog hook would use it.

Just a slightly different format that is directly digestible by another
system, while still preserving what the original messages in the file
would look like.

There are other ways to do it, but it's convenient. If we use, e.g.,
csv or json format, we lose the log_line_prefix and would need to
regenerate it from the individual fields.

Regards,
	Jeff Davis







^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Export log_line_prefix(); useful for emit_log_hook.
  2022-06-28 18:52 Export log_line_prefix(); useful for emit_log_hook. Jeff Davis <pgsql@j-davis.com>
@ 2022-06-29 13:09 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-04 06:54   ` Re: Export log_line_prefix(); useful for emit_log_hook. Michael Paquier <michael@paquier.xyz>
  1 sibling, 1 reply; 6+ messages in thread

From: Alvaro Herrera @ 2022-06-29 13:09 UTC (permalink / raw)
  To: Jeff Davis <pgsql@j-davis.com>; +Cc: pgsql-hackers

On 2022-Jun-28, Jeff Davis wrote:

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

Hmm, maybe your hypothetical book would prefer to use a different
setting for log line prefix than Log_line_prefix, so it would make sense
to pass the format string as a parameter to the function instead of
relying on the GUC global.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"Java is clearly an example of money oriented programming"  (A. Stepanov)





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Export log_line_prefix(); useful for emit_log_hook.
  2022-06-28 18:52 Export log_line_prefix(); useful for emit_log_hook. Jeff Davis <pgsql@j-davis.com>
  2022-06-29 13:09 ` Re: Export log_line_prefix(); useful for emit_log_hook. Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2022-07-04 06:54   ` Michael Paquier <michael@paquier.xyz>
  2022-07-04 20:24     ` Re: Export log_line_prefix(); useful for emit_log_hook. Jeff Davis <pgsql@j-davis.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Michael Paquier @ 2022-07-04 06:54 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: Jeff Davis <pgsql@j-davis.com>; pgsql-hackers

On Wed, Jun 29, 2022 at 03:09:42PM +0200, Alvaro Herrera wrote:
> Hmm, maybe your hypothetical book would prefer to use a different
> setting for log line prefix than Log_line_prefix, so it would make sense
> to pass the format string as a parameter to the function instead of
> relying on the GUC global.

+1.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Export log_line_prefix(); useful for emit_log_hook.
  2022-06-28 18:52 Export log_line_prefix(); useful for emit_log_hook. Jeff Davis <pgsql@j-davis.com>
  2022-06-29 13:09 ` Re: Export log_line_prefix(); useful for emit_log_hook. Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-04 06:54   ` Re: Export log_line_prefix(); useful for emit_log_hook. Michael Paquier <michael@paquier.xyz>
@ 2022-07-04 20:24     ` Jeff Davis <pgsql@j-davis.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Jeff Davis @ 2022-07-04 20:24 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-hackers

On Mon, 2022-07-04 at 15:54 +0900, Michael Paquier wrote:
> On Wed, Jun 29, 2022 at 03:09:42PM +0200, Alvaro Herrera wrote:
> > Hmm, maybe your hypothetical book would prefer to use a different
> > setting for log line prefix than Log_line_prefix, so it would make
> > sense
> > to pass the format string as a parameter to the function instead of
> > relying on the GUC global.

That is nicer, attached.

I also renamed the function log_status_format(), and made
log_line_prefix() a thin wrapper over that. I think that's less
confusing.

Regards,
	Jeff Davis

Attachments:

v2-0001-Provide-log_status_format-useful-for-an-emit_log_hoo.patch (text/x-patch, 2.3K) download From 4c64049e500c80ac495732d34ae56e07393115fe Mon Sep 17 00:00:00 2001 From: Jeff Davis <jeff@j-davis.com> Date: Tue, 28 Jun 2022 11:39:33 -0700 Subject: [PATCH] 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. --- src/backend/utils/error/elog.c | 15 ++++++++++++--- src/include/utils/elog.h | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 55ee5423afb..7b2bb9c8b75 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -2439,10 +2439,19 @@ 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, char *format, ErrorData *edata) { /* static counter for line numbers */ static long log_line_number = 0; @@ -2466,10 +2475,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 f5c6cd904de..e88e3f8a801 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_status_format(StringInfo buf, char *format, ErrorData *edata); extern void DebugFileOpen(void); extern char *unpack_sql_state(int sql_state); extern bool in_error_recursion_trouble(void); -- 2.17.1
^ permalink raw reply [nested|flat] 6+ messages in thread


end of thread, other threads:[~2022-07-04 20:24 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-06-28 18:52 Export log_line_prefix(); useful for emit_log_hook. Jeff Davis <pgsql@j-davis.com>
2022-06-29 01:17 ` Michael Paquier <michael@paquier.xyz>
2022-06-29 05:32   ` Jeff Davis <pgsql@j-davis.com>
2022-06-29 13:09 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2022-07-04 06:54   ` Michael Paquier <michael@paquier.xyz>
2022-07-04 20:24     ` Jeff Davis <pgsql@j-davis.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox