简体   繁体   English

PHP Windows 上的错误日志文件格式(php.ini error_log 指令)

[英]PHP Error log file format (php.ini error_log directive) on Windows

For an example:例如:
php.ini file php.ini 文件

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

Error log file (c:/php/php.log) contains every entry in this format:错误日志文件 (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

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 PHP 版本5.3.6
Apache/ 2.2.15 (Win32)阿帕奇/ 2.2.15 (Win32)
Tested on Windows 7 Home Basic and Windows XP SP3, same results.在 Windows 7 Home Basic 和 Windows XP SP3 上测试,结果相同。

php.ini file contains only two strings php.ini 文件仅包含两个字符串

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

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

PS. PS。

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

Everything works as expected.一切都按预期工作。
nginx phpinfo() script -> http://pastehtml.com/view/awvwvk9p9.html nginx phpinfo() 脚本 -> http://pastehtml.com/view/awvwvk9p9.html

There are more ini directives to control the output into the error log.还有更多的 ini 指令来控制 output 进入错误日志。 These are explained on this PHP manual page .这些在PHP 手册页上进行了解释。

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.默认情况下,PHP 在不加载 ini 并且仅设置了error_log并启用日志记录的情况下运行,它只执行 output 单行。 You can test that on your system as well, it demonstrates it well for the Command Line Interface (CLI) "Server Application Programming Interface (API) [SAPI]":你也可以在你的系统上测试它,它很好地演示了命令行接口(CLI)“服务器应用程序编程接口(API)[SAPI]”:

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.使用此命令进行隔离运行并将其与您的 output 进行比较。 If it has two line endings as well, then this is probably a bug of your php version.如果它也有两个行尾,那么这可能是您的 php 版本的错误。

If not a problem with the PHP version [ not the case in the original posting (OP)] then within your application some settings looks to be altered.如果 PHP 版本没有问题 [不是原始发布 (OP) 中的情况],那么在您的应用程序中,一些设置看起来会被更改。 You need to find out which setting.您需要找出哪个设置。 Probably you can find it by registering an own error handler and then dumping the ini settings.可能您可以通过注册自己的错误处理程序然后转储 ini 设置来找到它。

Last but not least, if it isn't a misunderstanding of the line ending (see my comment), then one may want to also look in the ini settings named error_prepend_string and error_append_string regarding the error display (but not the error logging).最后但并非最不重要的一点是,如果这不是对行尾的误解(请参阅我的评论),那么人们可能还想查看名为error_prepend_stringerror_append_string的有关错误显示的 ini 设置(但不是错误日志记录)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM