Re: print in plpython not appearing in logs

From: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
To: Ludwig Isaac Lim <ludz_lim(at)yahoo(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: print in plpython not appearing in logs
Date: 2022-12-13 21:20:04
Message-ID: CA+i5JwYCBeZ+dVR-LgV=dhyUjKNJ_TSRu3xeatZofnsRj6X4tg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

What is brilliant about plpython? Any brilliant examples to look at?

On Friday, 2 December 2022, Ludwig Isaac Lim <ludz_lim(at)yahoo(dot)com> wrote:

> 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
>
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Zheng Li 2022-12-13 22:25:48 Re: Support logical replication of DDLs
Previous Message Michel Pelletier 2022-12-13 18:59:07 Re: Is there a way to detect that code is inside CREATE EXTENSION?