我有这个PHP代码:
error_log('my message 1');
....
error_log('my message 2');
...
error_log('my message 3');
这会在 apache 中生成error_log包含所有消息的一行:
[Wed Nov 13 17:24:55.880399 2013] [proxy_fcgi:error] [pid xx] [client xxx] AH01071: Got error 'PHP message: my message 1'n'PHP message: my message 2'n'PHP message: my message 3
我的配置 :
Apache 2.4
PHP : 5.4
PHP-FPM with proxypassmatch directive.
我的问题:为什么消息在同一行上,以及如何每条消息有一行?
感谢您的回答。
编辑
每条消息一行应如下所示:
[Wed Nov 13 17:24:55.880399 2013] [proxy_fcgi:error] [pid xx] [client xxx] AH01071: Got error 'PHP message: my message 1'
[Wed Nov 13 17:24:55.880399 2013] [proxy_fcgi:error] [pid xx] [client xxx] AH01071: Got error 'PHP message: my message 2'
[Wed Nov 13 17:24:55.880399 2013] [proxy_fcgi:error] [pid xx] [client xxx] AH01071: Got error 'PHP message: my message 3'
error_log("error message 'r'n");
PHP 忽略单引号中的特殊 ASCII 字符(它将其呈现为单独的字符),您需要使用双引号。
另外:你应该打开你的 php.ini 文件,即/etc/php5/apache2/文件夹中的文件,并将 error_log
指令更改为指向一个文件。
,Apache将有足够的权限写入此文件。所以 chown www-data:www-data /var/www/somefile.log
应该这样做
如果当前未定义,日志将通过 syslog,并且不允许新行。
附加编辑:要穿透输出缓冲,您需要引发异常。
例:
try{
ob_start();
doSomething($userInput);
ob_end_flush();
}
catch(Exception $e){
error_log($e->getMessage());
}
function doSomething($data = null){
if($data === null){
throw new Exception("Data is required");
}
else{
//do something
}
}
User ''
r'
error_log("my message 1'r'n");
....
error_log("my message 2'r'n");
...
error_log("my message 3'r'n");