Debugging ‘No writers were added’ error

Recently I got some

PHP Fatal error: Uncaught exception 'Zend_Log_Exception' with message 'No writers were added'

messages in the Apache error log file. The reason is most of the time (at least in my projects) is that the Zend_Log_Writer_Stream constructor returns null. Just a reminder to myself how to solve the problem:

  1. make sure the path to the file exists
  2. if that didn’t help, make sure the file exists
  3. if that didn’t help, make sure the file is writeable by www-data.
    sudo chown www-data file.log and sudo chmod u+w file.log should do the trick.
  4. if that didn’t help, make sure the file is writeable by others.
    sudo chmod o+w file.log should do the trick.
    (No. This one should not be done. It’s bad practice, insecure, and everything. It can be used only to test that after so many hours of debugging I’m still sane, and file permissions aren’t the issue here. Or to figure out that in this particular case it isn’t www-data who wants to write the file, but some other user, for example because it’s a command line PHP script running as another user.)
  5. if that didn’t help, make sure the file isn’t open anywhere else. In my case the problem was that there was a Zend_Log descendant singleton which held a static copy of the Zend_Log_Writer_Stream which never got closed. (As an irrelevant note, we should do code reviews more often.)

Leave a Reply

Your email address will not be published. Required fields are marked *