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:
- make sure the path to the file exists
- if that didn’t help, make sure the file exists
- if that didn’t help, make sure the file is writeable by
sudo chown www-data file.logand
sudo chmod u+w file.logshould do the trick.
if that didn’t help, make sure the file is writeable by others.(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
sudo chmod o+w file.logshould do the trick.
www-datawho wants to write the file, but some other user, for example because it’s a command line PHP script running as another user.)
- 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_Logdescendant singleton which held a static copy of the
Zend_Log_Writer_Streamwhich never got closed. (As an irrelevant note, we should do code reviews more often.)