Read Time:1 Minute, 14 Second
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
www-data
.sudo chown www-data file.log
andsudo chmod u+w file.log
should 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’tsudo chmod o+w file.log
should do the trick.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.)- 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 theZend_Log_Writer_Stream
which never got closed. (As an irrelevant note, we should do code reviews more often.)