我在Kohana::$log上得到错误“调用非对象上的成员函数add()”
在application/logs目录中没有登录。我描述的错误是在apache error_log上找到的。它就是这样出现的
Fri 17:07:09 2012 client MY.IPA.DDR.ESS PHP致命错误:在第8行的非对象上调用成员函数add()
这是我的错误控制器。
<?php
class Kohana_Exception extends Kohana_Kohana_Exception {
public static function handler(Exception $e) {
if (Kohana::DEVELOPMENT === Kohana::$environment) {
parent::handler($e);
} else {
try {
Kohana::$log->add(Log::ERROR, "own exception handler");
Kohana::$log->add(Log::ERROR, parent::text($e));
$attributes = array('action' => 500, 'message' => rawurlencode($e->getMessage()));
if ($e instanceof HTTP_Exception) {
$attributes['action'] = $e->getCode();
}
// Error sub-request.
echo Request::factory(Route::get('error')->uri($attributes))->execute()->send_headers()->body();
}
catch(Exception $e) {
// Clean the output buffer if one exists
ob_get_level() and ob_clean();
// Display the exception text
echo parent::text($e);
// Exit with an error status
exit(1);
}
}
}
}从代码来看,Kohana::$log似乎还没有初始化。但这段代码已经运行了很长时间。是什么让它不起作用的?
我使用Kohana-3.2和PHP5.3.13在Fedora 15上使用
发布于 2012-08-17 23:38:56
我已经解决了这个问题。如果这个问题发生在任何其他kohana开发人员身上,而他是从google来到这里的,这就是解决方案。
从根shell运行以下命令。记住,如果重新启动服务器,就必须再次运行它。
setsebool -P httpd_unified 1附加信息:如何追踪。
检查这些位置
/var/log/messages。如果它的SElinux问题,您将在/var/log/messages上找到日志条目。这就是我得到的。
Se疑难解答: /var/www/html/application/cache.目录下的SELinux正在阻止/usr/sbin/httpd写访问以获得完整的SELinux消息。运行-l 087dfdb5-c7de-4238-8e6b-a713213a456d
如前所述,运行sealert -l 087dfdb5-c7de-4238-8e6b-a713213a456d将显示我编写的作为解决方案的命令。
发布于 2012-08-17 23:09:04
试着看看是否:
Log::instance()->add(Log::ERROR, "own exception handler");很管用。当前的Kohana文档似乎表明使用$log仍然有效,但是在异常处理之前它可能会被取消设置。但是,从Log类检索实例在任何时候都是可用的。
发布于 2017-09-12 13:42:04
你可能有权限问题。在我的例子中,无法访问项目文件的是httpd服务(apache2)。下面是一个残酷的解决方案(只有在安全情况允许的情况下才能这样做):
$ sudo 0777 /var/www/html/mysite/
来自:file gives "failed to open stream: Permission denied " error after all configurations i did
https://stackoverflow.com/questions/12013929
复制相似问题