I created a small framework to do autonomous transactions in PostgreSQL using dblink. I use this to write to a log table regardless if the surrounding transaction rollbacks or not. Very handy to instrument your stored functions and other logic with calls to log to the table.
https://github.com/henkbl/plog