Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gate long STATEMENT log in any error #123

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
From 2c80b43e91b812fd7083801eca5b0b8f41d0c178 Mon Sep 17 00:00:00 2001
From: Fantix King <[email protected]>
Date: Thu, 14 Nov 2024 19:44:01 -0500
Subject: [PATCH 6/6] Truncate long STATEMENT/QUERY log

---
src/backend/utils/error/elog.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 8d33686510a..ae186e79a29 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -185,6 +185,7 @@ static void write_pipe_chunks(char *data, int len, int dest);
static void send_message_to_frontend(ErrorData *edata);
static const char *error_severity(int elevel);
static void append_with_tabs(StringInfo buf, const char *str);
+static void append_n_with_tabs(StringInfo buf, const char *str, int n);


/*
@@ -3065,7 +3066,7 @@ send_message_to_server_log(ErrorData *edata)
{
log_line_prefix(&buf, edata);
appendStringInfoString(&buf, _("QUERY: "));
- append_with_tabs(&buf, edata->internalquery);
+ append_n_with_tabs(&buf, edata->internalquery, 1024);
appendStringInfoChar(&buf, '\n');
}
if (edata->context && !edata->hide_ctx)
@@ -3110,7 +3111,7 @@ send_message_to_server_log(ErrorData *edata)
{
log_line_prefix(&buf, edata);
appendStringInfoString(&buf, _("STATEMENT: "));
- append_with_tabs(&buf, debug_query_string);
+ append_n_with_tabs(&buf, debug_query_string, 1024);
appendStringInfoChar(&buf, '\n');
}

@@ -3551,6 +3552,32 @@ append_with_tabs(StringInfo buf, const char *str)
}


+/*
+ * append_n_with_tabs
+ *
+ * Append the string to the StringInfo buffer truncating at n characters,
+ * inserting a tab after any newline, and `...` at the end if truncated.
+ */
+static void
+append_n_with_tabs(StringInfo buf, const char *str, int n)
+{
+ char ch;
+
+ while ((ch = *str++) != '\0' && n > 0)
+ {
+ appendStringInfoCharMacro(buf, ch);
+ if (ch == '\n')
+ appendStringInfoCharMacro(buf, '\t');
+ n--;
+ }
+ if (ch != '\0') {
+ appendStringInfoCharMacro(buf, '.');
+ appendStringInfoCharMacro(buf, '.');
+ appendStringInfoCharMacro(buf, '.');
+ }
+}
+
+
/*
* Write errors to stderr (or by equal means when stderr is
* not available). Used before ereport/elog can be used
--
2.47.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
From 38b74895b1dbbad3c6fa935cbb3f77f449b8d5ea Mon Sep 17 00:00:00 2001
From: Fantix King <[email protected]>
Date: Thu, 14 Nov 2024 19:44:01 -0500
Subject: [PATCH 6/6] Truncate long STATEMENT/QUERY log

---
src/backend/utils/error/elog.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 01066832e18..4bad03460e4 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -180,6 +180,7 @@ 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);
+static void append_n_with_tabs(StringInfo buf, const char *str, int n);


/*
@@ -2876,7 +2877,7 @@ send_message_to_server_log(ErrorData *edata)
{
log_line_prefix(&buf, edata);
appendStringInfoString(&buf, _("QUERY: "));
- append_with_tabs(&buf, edata->internalquery);
+ append_n_with_tabs(&buf, edata->internalquery, 1024);
appendStringInfoChar(&buf, '\n');
}
if (edata->context && !edata->hide_ctx)
@@ -2919,7 +2920,7 @@ send_message_to_server_log(ErrorData *edata)
{
log_line_prefix(&buf, edata);
appendStringInfoString(&buf, _("STATEMENT: "));
- append_with_tabs(&buf, debug_query_string);
+ append_n_with_tabs(&buf, debug_query_string, 1024);
appendStringInfoChar(&buf, '\n');
}

@@ -3365,6 +3366,32 @@ append_with_tabs(StringInfo buf, const char *str)
}


+/*
+ * append_n_with_tabs
+ *
+ * Append the string to the StringInfo buffer truncating at n characters,
+ * inserting a tab after any newline, and `...` at the end if truncated.
+ */
+static void
+append_n_with_tabs(StringInfo buf, const char *str, int n)
+{
+ char ch;
+
+ while ((ch = *str++) != '\0' && n > 0)
+ {
+ appendStringInfoCharMacro(buf, ch);
+ if (ch == '\n')
+ appendStringInfoCharMacro(buf, '\t');
+ n--;
+ }
+ if (ch != '\0') {
+ appendStringInfoCharMacro(buf, '.');
+ appendStringInfoCharMacro(buf, '.');
+ appendStringInfoCharMacro(buf, '.');
+ }
+}
+
+
/*
* Write errors to stderr (or by equal means when stderr is
* not available). Used before ereport/elog can be used
--
2.47.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
From 19e6ae523ab82adf8f256ed2dd892183c2d20593 Mon Sep 17 00:00:00 2001
From: Fantix King <[email protected]>
Date: Thu, 14 Nov 2024 19:44:01 -0500
Subject: [PATCH 6/6] Truncate long STATEMENT/QUERY log

---
src/backend/utils/error/elog.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 7112fb00069..b0326ba3649 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -192,6 +192,7 @@ 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);
+static void append_n_with_tabs(StringInfo buf, const char *str, int n);


/*
@@ -3218,7 +3219,7 @@ send_message_to_server_log(ErrorData *edata)
{
log_line_prefix(&buf, edata);
appendStringInfoString(&buf, _("QUERY: "));
- append_with_tabs(&buf, edata->internalquery);
+ append_n_with_tabs(&buf, edata->internalquery, 1024);
appendStringInfoChar(&buf, '\n');
}
if (edata->context && !edata->hide_ctx)
@@ -3261,7 +3262,7 @@ send_message_to_server_log(ErrorData *edata)
{
log_line_prefix(&buf, edata);
appendStringInfoString(&buf, _("STATEMENT: "));
- append_with_tabs(&buf, debug_query_string);
+ append_n_with_tabs(&buf, debug_query_string, 1024);
appendStringInfoChar(&buf, '\n');
}

@@ -3707,6 +3708,32 @@ append_with_tabs(StringInfo buf, const char *str)
}


+/*
+ * append_n_with_tabs
+ *
+ * Append the string to the StringInfo buffer truncating at n characters,
+ * inserting a tab after any newline, and `...` at the end if truncated.
+ */
+static void
+append_n_with_tabs(StringInfo buf, const char *str, int n)
+{
+ char ch;
+
+ while ((ch = *str++) != '\0' && n > 0)
+ {
+ appendStringInfoCharMacro(buf, ch);
+ if (ch == '\n')
+ appendStringInfoCharMacro(buf, '\t');
+ n--;
+ }
+ if (ch != '\0') {
+ appendStringInfoCharMacro(buf, '.');
+ appendStringInfoCharMacro(buf, '.');
+ appendStringInfoCharMacro(buf, '.');
+ }
+}
+
+
/*
* Write errors to stderr (or by equal means when stderr is
* not available). Used before ereport/elog can be used
--
2.47.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
From a5969a9f10e83a28154d1d8297babd2b31170dc0 Mon Sep 17 00:00:00 2001
From: Fantix King <[email protected]>
Date: Thu, 14 Nov 2024 19:44:01 -0500
Subject: [PATCH 6/6] Truncate long STATEMENT/QUERY log

---
src/backend/utils/error/elog.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index b924b524d0b..2246e8f6047 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -191,6 +191,7 @@ 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);
+static void append_n_with_tabs(StringInfo buf, const char *str, int n);


/*
@@ -3237,7 +3238,7 @@ send_message_to_server_log(ErrorData *edata)
{
log_line_prefix(&buf, edata);
appendStringInfoString(&buf, _("QUERY: "));
- append_with_tabs(&buf, edata->internalquery);
+ append_n_with_tabs(&buf, edata->internalquery, 1024);
appendStringInfoChar(&buf, '\n');
}
if (edata->context && !edata->hide_ctx)
@@ -3280,7 +3281,7 @@ send_message_to_server_log(ErrorData *edata)
{
log_line_prefix(&buf, edata);
appendStringInfoString(&buf, _("STATEMENT: "));
- append_with_tabs(&buf, debug_query_string);
+ append_n_with_tabs(&buf, debug_query_string, 1024);
appendStringInfoChar(&buf, '\n');
}

@@ -3729,6 +3730,32 @@ append_with_tabs(StringInfo buf, const char *str)
}


+/*
+ * append_n_with_tabs
+ *
+ * Append the string to the StringInfo buffer truncating at n characters,
+ * inserting a tab after any newline, and `...` at the end if truncated.
+ */
+static void
+append_n_with_tabs(StringInfo buf, const char *str, int n)
+{
+ char ch;
+
+ while ((ch = *str++) != '\0' && n > 0)
+ {
+ appendStringInfoCharMacro(buf, ch);
+ if (ch == '\n')
+ appendStringInfoCharMacro(buf, '\t');
+ n--;
+ }
+ if (ch != '\0') {
+ appendStringInfoCharMacro(buf, '.');
+ appendStringInfoCharMacro(buf, '.');
+ appendStringInfoCharMacro(buf, '.');
+ }
+}
+
+
/*
* Write errors to stderr (or by equal means when stderr is
* not available). Used before ereport/elog can be used
--
2.47.0