How to write to error log file in PHP

Vasant picture Vasant · Mar 20, 2013 · Viewed 167.8k times · Source

I want to write a message to an error log file when executing PHP code.

I am trying to use the PHP error_log() function Docs.

But it's not working properly for me.

Answer

suspectus picture suspectus · Mar 20, 2013

If you don't want to change anything in your php.ini file, according to PHP documentation, you can do this.

error_log("Error message\n", 3, "/mypath/php.log");

The first parameter is the string to be sent to the log. The second parameter 3 means expect a file destination. The third parameter is the log file path.