From: Ludwig Isaac Lim <ludz_lim@yahoo.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: print in plpython not appearing in logs
Date: Fri, 2 Dec 2022 11:59:18 +0000 (UTC)
Message-ID: <1649936435.214554.1669982358413@mail.yahoo.com> (raw)
References: <1649936435.214554.1669982358413.ref@mail.yahoo.com>
I'm having problems wherein my print() statements inside my plpython stored proc are not appearing in postgresql log. I tried setting the file=sys.stderr
To reproduce:
CREATE OR REPLACE PROCEDURE p_ludwig_test()
AS
$$
import sys
try:
x = 1 / 0
except:
plpy.log("hello")
print("oink oink", file=sys.stderr)
print("oink oink - v2")
plpy.log("haha")
$$
LANGUAGE plpython3u;
call p_ludwig_test()
Output:
---------------------
2022-12-02 11:46:11.324 UTC [19390] LOG: hello
2022-12-02 11:46:11.324 UTC [19390] CONTEXT: PL/Python procedure "p_ludwig_test"
2022-12-02 11:46:11.324 UTC [19390] STATEMENT: call p_ludwig_test();
2022-12-02 11:46:11.324 UTC [19390] LOG: haha
2022-12-02 11:46:11.324 UTC [19390] CONTEXT: PL/Python procedure "p_ludwig_test"
2022-12-02 11:46:11.324 UTC [19390] STATEMENT: call p_ludwig_test();
Notice that the "oink oink" is not there.
Relevant logging configuration:
logging_collector = on
log_directory = 'logs'
log_min_messages = info
log_min_error_statement = error
PG version
-------------------
PostgreSQL 14.6 on aarch64-unknown-linux-gnu, compiled by gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-15), 64-bit
The reason why I'm trying to use print() is because plpy logger is quite verbose. Each logging will output 3 line
for example:
plpy.log("hello")
Will generate the following 3 lines in the log:
2022-12-02 11:46:11.324 UTC [19390] LOG: hello
2022-12-02 11:46:11.324 UTC [19390] CONTEXT: PL/Python procedure "p_ludwig_test"
2022-12-02 11:46:11.324 UTC [19390] STATEMENT: call p_ludwig_test();
Another thing is there is another stored procedure that I have wherein the print() to stderr actually works, so I'm not sure what I'm doing wrong.
Thank you in advance,
Ludwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: ludz_lim@yahoo.com
Subject: Re: print in plpython not appearing in logs
In-Reply-To: <1649936435.214554.1669982358413@mail.yahoo.com>
References: <1649936435.214554.1669982358413.ref@mail.yahoo.com> <1649936435.214554.1669982358413@mail.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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