Windows 上的 PHP 错误日志文件格式(php.ini error_log 指令)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6321465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Error log file format (php.ini error_log directive) on Windows
提问by Sergey L
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
Apache/2.2.15(Win32)
Tested on Windows 7 Home Basic and Windows XP SP3, same results.
PHP 版本5.3.6
Apache/ 2.2.15(Win32)
在 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.
附注。
sever: nginx 1.0.4
FastCGI + PHP Version 5.3.6
服务器:nginx 1.0.4
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
回答by hakre
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.
有更多的 ini 指令来控制输出到错误日志中。如果不是对行尾的误解(请参阅我的评论),那么您可能需要查看error_prepend_string
and的 ini 设置error_append_string
。这两个和更多相关的设置在这个 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. You can test that on your system as well:
默认情况下,PHP 在不加载 ini 并且只error_log
启用设置和日志记录的情况下运行,它只输出一行。您也可以在您的系统上进行测试:
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.
使用此命令进行隔离运行并将其与您的输出进行比较。如果它也有两个行结尾,那么这可能是您的 php 版本的错误。
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 handlerand then duming the ini settings.
如果不是,那么在您的应用程序中,某些设置看起来会被更改。您需要找出哪个设置。可能您可以通过注册自己的错误处理程序然后复制 ini 设置来找到它。