Error logging with information about local time and line break at the end

I need to write local time information, error message in php log file. I do not know why I cannot get the format correctly. I am using a script:

  error_log('['.date("F j, Y, g:i a").']'.$msg." <br>", 3,  $phperrorPath);

There are two problems with this:

  • The date is not recorded in local time, but the default time is GMT + 0; I want to write machine time information to a log
  • After the file is written, it is not split into another line.

How to change this code?

+3
source share
3 answers

Set your local time using date_default_timezone_set:

date_default_timezone_set('UTC');

Adding the format parameters e and O to the call datewill give you the time zone identifier and clockwise offset:

date("F j, Y, g:i a e O")

"\n" :

//I've left in the HTML line break
error_log('['.date("F j, Y, g:i a e O").']'.$msg."<br /> \n", 3,  $phperrorPath); 

"3" error_log, "0" , php.ini. "2" , , - . :

http://php.net/manual/en/function.error-log.php

, localtime

+6

"2", , , HTML
\n. , .

+1

:

date_default_timezone_set('MYT');

This will set the time zone script in Kuala Lumpur, Malaysia (this is your profile country).

Then use:

error_log('['.date("F j, Y, g:i a e O").']'.$msg."<br />\r\n",3,$phperrorPath);

I do not know if you want to leave an HTML tag, so I left it there.

+1
source

Source: https://habr.com/ru/post/1711725/


All Articles