开发者

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

A login function writes a couple of session variables after successful authentication and then redirects to itself to print a welcome message (the view changes based on authentication status). This works fine with debug >= 0. Now, when I add a CakeLog::write() to that same login function, it stops working with debug = 0 and an empty page is displayed. It continues working with debug > 0.

According to the Apache logs, the white page is the result of an error 500 following a POST request.

What does CakeLog::write() do apart from writing to a log file?

'Session', 'Security' and 'Auth' components are involv开发者_Python百科ed, but I do not call the requirePost method.

CakeLog::write() returns true if successful but catching the return code doesn't change the issue that further code execution is interrupted. I have to reload the white page in order to continue (i.e. replace the POST with a GET request).

Here is the users_controller's login:

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());
   }
  }

And this is the app_controller's 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[...]
 }


This is a long shot, but 'log' is not a valid log type so you could try again with something like 'notice'.

The only other thing I can think of is that the log file directory is not writeable by PHP. You could check that also.


Thanks @François, that pointed me into the right direction. It was necessary to set

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

to ensure that message and error logging works even if debug=0 (added this in bootstrap).
By the way the 1.3 cookbook exlicitely states that logging is enabled by default even if debug=0. That might be a glitch in the documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜