CakePHP-CakeLog::write()可以中断进一步的代码执行


CakePHP - Can CakeLog::write() break further code execution?

登录函数在成功身份验证后写入几个会话变量,然后重定向到自身以打印欢迎消息(视图根据身份验证状态而更改)。这适用于debug>=0。现在,当我向同一登录函数添加CakeLog::write()时,它在debug=0时停止工作,并显示一个空页面。它继续使用debug>0。

根据Apache日志,白色页面是POST请求后出现错误500的结果。

除了写入日志文件之外,CakeLog::write()还能做什么?

涉及"Session"、"Security"answers"Auth"组件,但我不调用requirePost方法。

如果成功,CakeLog::write()将返回true,但捕获返回代码不会改变进一步代码执行中断的问题。我必须重新加载白色页面才能继续(即用GET请求替换POST)。

这是users_controller的登录名:

function login(){
 [if form contains data do some LDAP checking...]
  if($permission>0){
   $this->Session->write('logname', $samaccountname);
   $this->Session->write('logperm', $permission);
   [...]
   // Here is where it blocks. Without this line debug=0 is okay
   $result = CakeLog::write('log', $samaccountname);
   $this->Auth->login();
   // the Auth redirect target is set in the app_controller to allow jumping right 
   // to the originally intended URL, usually it redirects to itself
   $this->redirect($this->Auth->redirect());
   }
  }

这是app_controller的beforeFilter:

function beforeFilter(){
 $this->Security->blackHoleCallback = 'showErrorPage';
 $this->Security->requireAuth();
 $this->Security->requireSecure();
 if($this->Session->read('logperm') < 1 && $this->here != '/users/login'){
  $this->Auth->redirect($this->here); // store chosen URL
  $this->redirect('/users/login');
  }
 if($this->Session->read('logperm') == 3)
  $this->Auth->allow('*');
 elseif[...]
 }

这是一个很长的机会,但'log'不是有效的日志类型,因此您可以使用类似'notice'的方法重试。

我唯一能想到的是,日志文件目录是PHP不可写的。你也可以检查一下。

谢谢@François,这给我指明了正确的方向。有必要设置

Configure::write('log', true);

以确保即使debug=0(已在引导程序中添加),消息和错误日志也能正常工作
顺便说一句,1.3食谱明确指出,即使debug=0,默认情况下也会启用日志记录。这可能是文档中的一个小故障。