我正在尝试将Zend Framework日志异常发送到一个文件,但它仍然说拒绝权限,即使我chmod'ed并检查路径。这是我的目录结构:
config/
autoload/
global.php
local.php
data/
logs/
error.log
我在Global.php中将Logger注册为服务,下面的代码就是我所拥有的:
'factories' => [
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
'Navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
'Zend\Log\Logger' => function($sm) {
$logger = new Zend\Log\Logger();
$writer = new Zend\Log\Writer\Stream('./data/logs/error.log');
$logger->addWriter($writer);
return $logger;
},
],
我不确定这是否也很重要,但这是调用它的代码,应用程序的module.php文件:
public function onBootstrap(MvcEvent $e)
{
$application = $e->getApplication();
$sm = $application->getServiceManager();
$eventManager = $e->getApplication()->getEventManager();
$sharedManager = $application->getEventManager()->getSharedManager();
$sharedManager->attach('Zend\Mvc\Application', 'dispatch.error', function($e) use ($sm) {
if ($e->getParam('exception')) {
$sm->get('Zend\Log\Logger')->crit($e->getParam('exception'));
}
});
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
更新 - 我对global.php
中的服务稍作修改'factories' => [
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
'Navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
'Zend\Log\Logger' => function($sm) {
chdir('./data/logs');
$logger = new Zend\Log\Logger();
$writer = new Zend\Log\Writer\Stream(getcwd() . '/' . 'error.log');
$logger->addWriter($writer);
Zend\Log\Logger::registerErrorHandler($logger);
return $logger;
},
],
任何帮助都将不胜感激。
谢谢!
答案 0 :(得分:0)
想出来,这是一个SELinux问题。谢谢!