0

I have a plpython trigger function and I'm trying to log something in it to better understand what it does, but I can't manage to print anything on the postgres log file. I have tried different level of printing (error, info, notice...) but the only one that does something is the plpy.fatal function, that raise an exception caught by the try-except.

Here an example of my function:

CREATE FUNCTION public.myfunction() RETURNS trigger
LANGUAGE plpythonu
AS $$
try:
 plpy.error("log error")
 plpy.info("log info")
 plpy.notice("log notice")
 if TD["event"] != "INSERT":
 return "OK"
 # do other stuff here
 except Exception, ex:
 #plpy.info("f_b_cli_after : %s" % ex)
 return None
$$;

Maybe I'm missing some parameter inside the postgresql.conf, this is what I have now configured:

log_destination = 'stderr'
logging_collector = on
log_directory = '/var/log/postgresql'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
client_min_messages = notice
log_min_messages = info
log_min_error_statement = info
log_statement = 'all'

The documentation I have found does not specify anything else and other answers on this subject here just says that plpy.notice is equivalent to raise notice, so I expected to work fine as it was.

Am I missing something?

asked Dec 5, 2023 at 10:49

2 Answers 2

0

I managed to print the logs by putting on debug:

client_min_messages = notice
log_min_messages = info
log_min_error_statement = info

But honestly I don't know if all three are needed or just one of them.

answered Jan 3, 2024 at 14:38
Sign up to request clarification or add additional context in comments.

Comments

-1

plpy.info will create an INFO message, plpy.notice a NOTICE message, and do on. Both INFO and NOTICE are messages intended for the client, not the log file, so they won't get logged (unless you change log_min_messages).

If you want to write a log entry, call plpy.log.

With your settings (which I wouldn't recommend) you will get INFO and NOTICE logged. So if you don't see any log messages, you either didn't reload PostgreSQL after editing the configuration, or you edited the wrong configuration file, or you are looking at the wrong log file.

answered Dec 5, 2023 at 11:48

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.