How to log psql executions with bash scriptpsq

Solution for How to log psql executions with bash scriptpsq
is Given Below:

I have several bash scripts that use either echo or psql psql "postgresql://XXXx" << 'EOF'.

In some of my bash scripts I use simple echo but sometimes in psql I use raise notices.

even if I don’t think I coded the right way (I wrote the sql scripts directly in the bash), I wish I could create a good log file to find my way around

I would like to be able to log all the texts. To my surprise ./toto.sh> toto.log does not work (permission problem) [but I have the same problem when I created the .log]

If possible, but it is not an obligation to be able to create clean logs (dated, etc.)

If you have any good advice or a good tutorial …

I am on debian. Bash scripts will be executed in cron task

thanking you