带有消息file.log的未捕获异常'Zend_Log_Exception'无法使用模式"a"打开

13 php zend-framework

我遇到以下错误:

带有消息file.log的未捕获异常'Zend_Log_Exception'无法使用模式"a"打开

在我的bootstrap中,我有以下代码:

$logfile = PROJECT_PATH . DIRECTORY_SEPARATOR .'/tmp/logs/'.$config->app->logfile.'.log';

if (!file_exists($logfile))
{
  $fp = fopen($logfile, 'a');
  fclose($fp);
}

$redacteur = new Zend_Log_Writer_Stream($logfile);
$logger    = new Zend_Log($redacteur);
Run Code Online (Sandbox Code Playgroud)

完整的错误页面:

警告:fopen(/home/http/me.tv/fbapps/www//tmp/logs/vengeance.log)[function.fopen]:无法打开流:/ home/http/me中没有这样的文件或目录.第81行的tv/fbapps/www/inline/bootstrap_vengeance.php

警告:fclose()要求参数1为资源,在第82行的/home/http/me.tv/fbapps/www/inline/bootstrap_vengeance.php中给出布尔值

致命错误:无法使用/ home/http/me中的模式"a"打开带有消息"/home/http/me.tv/fbapps/www//tmp/logs/vengeance.log"的未捕获异常"Zend_Log_Exception" .tv/fbapps/www/library/Zend/Log/Writer/Stream.php:78堆栈跟踪:#0 /home/http/me.tv/fbapps/www/inline/bootstrap_vengeance.php(85):Zend_Log_Writer_Stream-> __construct('/ home/http/medi ...')#1 /home/http/me.tv/fbapps/www/htdocs/vengeance/index.php(9):require_once('/ home/http/medi. ..')在第78行的/home/http/me.tv/fbapps/www/library/Zend/Log/Writer/Stream.php中抛出#2 {main}

j0k*_*j0k 19

在文件上放置正确的权限:0777.

检查目录是否/home/http/me.tv/fbapps/www/tmp/logs/存在,然后在终端中运行此命令:

chmod 777 /home/http/me.tv/fbapps/www/tmp/logs/vengeance.log
Run Code Online (Sandbox Code Playgroud)

  • 通过引入安全漏洞解决问题不是可接受的解决方案。只需将正确的权利授予正确的用户即可。 (3认同)
  • 我在整个目录上拥有权限'755',文件不存在.将目录的权限更改为"777"解决了该问题. (2认同)
  • 如果您根据日期创建日志文件,这不是一个很好的解决方案 (2认同)