I need to write the local time information , the exception message to a php log file. I don’t know why I can’t get the format correct. The script I use is this:
error_log('['.date("F j, Y, g:i a").']'.$msg." <br>", 3, $phperrorPath);
There are two problem with this:
- The date is not written in local time, instead it’s default to the GMT+0 time; I want to write the machine time information to the log
- After the file is written, it’s not break to another line.
How to modify this code?
Set your local time using
date_default_timezone_set:Adding the e and O format parameters to the
datecall will give you the timezone identifier and GMT offset:Add a “\n” to the end of the string:
Lines will not be concatenated when using “3” as the second argument to
error_log, and using “0” will write the output to the default location specified in php.ini. “2” is no longer an option, so I think manually concatenating the line break is the way to go. See:http://php.net/manual/en/function.error-log.php
Also, take a look at localtime