Windows上的PHP错误日志文件格式(php.ini error_log指令) [英] PHP Error log file format (php.ini error_log directive) on Windows

查看:187
本文介绍了Windows上的PHP错误日志文件格式(php.ini error_log指令)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:
php.ini文件

...
; Log errors to specified file.
error_log = c:/php/php.log
...

错误日志文件(c:/php/php.log)包含以下格式的每个条目:

[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

两个回车符,每错误一条线换一行.

为什么会这样? 如何将错误日志文件更改为默认格式:

[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版本 5.3.6
Apache/ 2.2.15 (Win32)
在Windows 7 Home Basic和Windows XP SP3上进行了测试,结果相同.

php.ini文件仅包含两个字符串

log_errors = On
error_log = c:/server/php.log

apache phpinfo()脚本-> http://pastehtml.com/view/awvx1vgpp.html

PS.

服务器:nginx 1.0.4
FastCGI + PHP版本 5.3.6

一切正常.
nginx phpinfo()脚本-> http://pastehtml.com/view/awvwvk9p9.html

解决方案

还有更多的ini指令来控制输出到错误日志中.如果不是对行尾有误解(请参阅我的评论),那么您可能需要查看error_prepend_stringerror_append_string的ini设置.在此PHP手册页中说明了这两个及更多相关的设置. /p>

默认情况下,PHP运行时未加载ini且仅设置了error_log并启用了日志记录,因此它仅输出一行.您也可以在系统上进行测试:

php -n -d error_log=./error.log -d log_errors=1 -r 'error;'

使用此命令进行隔离运行,并将其与您的输出进行比较.如果它也有两个行尾,那么这可能是您的php版本的错误.

如果没有,那么在您的应用程序中,某些设置似乎需要更改.您需要找出哪个设置.可能可以通过注册自己的错误处理程序来找到它,然后设置ini设置为空.

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

解决方案

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.

这篇关于Windows上的PHP错误日志文件格式(php.ini error_log指令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆