skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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.


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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search