backtrace_functions emits trace for any elog

Started by Ilya Gladyshevover 2 years ago2 messages
#1Ilya Gladyshev
ilya.v.gladyshev@gmail.com
1 attachment(s)

Hi,
I used backtrace_functions to debug one of my ideas and found its behavior counter-intuitive and contradictory to it own docs. I think the GUC is supposed to be used to dump backtrace only on elog(ERROR) (should it also be done for higher levels? not sure about this), but, in fact, it does that for any log-level. I have attached a patch that checks log-level before attaching backtrace.

Regards,
Ilya

Attachments:

0001-check-elevel-before-attaching-backtrace.patchapplication/octet-stream; name=0001-check-elevel-before-attaching-backtrace.patch; x-unix-mode=0644Download
From 911c553afbe9bf9962bde3f61c10410487d8b918 Mon Sep 17 00:00:00 2001
From: Ilya Gladyshev <ilya.v.gladyshev@gmail.com>
Date: Mon, 4 Sep 2023 21:25:23 +0100
Subject: [PATCH] check elevel before attaching backtrace

---
 src/backend/utils/error/elog.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 8e1f3e8521..5b1372568a 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -500,6 +500,7 @@ errfinish(const char *filename, int lineno, const char *funcname)
 	if (!edata->backtrace &&
 		edata->funcname &&
 		backtrace_functions &&
+		elevel == ERROR &&
 		matches_backtrace_functions(edata->funcname))
 		set_backtrace(edata, 2);
 
-- 
2.39.2 (Apple Git-143)

#2Noah Misch
noah@leadboat.com
In reply to: Ilya Gladyshev (#1)
Re: backtrace_functions emits trace for any elog

On Mon, Sep 04, 2023 at 09:30:32PM +0100, Ilya Gladyshev wrote:

I used backtrace_functions to debug one of my ideas and found its behavior counter-intuitive and contradictory to it own docs. I think the GUC is supposed to be used to dump backtrace only on elog(ERROR) (should it also be done for higher levels? not sure about this), but, in fact, it does that for any log-level. I have attached a patch that checks log-level before attaching backtrace.

This would make the feature much less useful. Better to change the docs.