问题
For an example:
php.ini file
... ; Log errors to specified file. error_log = c:/php/php.log ...
Error log file (c:/php/php.log) contains every entry in this format:
[12-Jun-2011 12:58:55] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n [12-Jun-2011 12:59:01] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n [12-Jun-2011 13:01:12] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n [12-Jun-2011 13:02:11] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n [12-Jun-2011 13:11:23] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n [12-Jun-2011 13:12:10] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n
Two carriage return character and one new line per one error line.
Why it happens? How to change error log file to default format:
[12-Jun-2011 12:58:55] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\n [12-Jun-2011 12:59:01] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\n [12-Jun-2011 13:01:12] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\n [12-Jun-2011 13:02:11] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\n [12-Jun-2011 13:11:23] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\n [12-Jun-2011 13:12:10] PHP Notice: Undefined variable: test in C:\www\phpinfo.php on line 2\r\n
PHP Version 5.3.6
Apache/2.2.15 (Win32)
Tested on Windows 7 Home Basic and Windows XP SP3, same results.
php.ini file contains only two strings
log_errors = On error_log = c:/server/php.log
apache phpinfo() script -> http://pastehtml.com/view/awvx1vgpp.html
PS.
sever: nginx 1.0.4
FastCGI + PHP Version 5.3.6
Everything works as expected.
nginx phpinfo() script -> http://pastehtml.com/view/awvwvk9p9.html
回答1:
There are more ini directives to control the output into the error log. If it's not a misunderstanding of the line ending (see my comment), then you might want to look in the ini settings of error_prepend_string
and error_append_string
. Those two and more related settings are explained on this PHP manual page.
By default, PHP running with not loading the ini and only having the error_log
set and logging enabled, it does output a single line only. You can test that on your system as well:
php -n -d error_log=./error.log -d log_errors=1 -r 'error;'
Use this command to make an isolated run and compare it with your output. If it has two line endings as well, then this is probably a bug of your php version.
If not then within your application some settings looks to be altered. You need to find out which setting. Probably you can find it by registering an own error handler and then duming the ini settings.
来源:https://stackoverflow.com/questions/6321465/php-error-log-file-format-php-ini-error-log-directive-on-windows