Zend_Log with multiple writers

eschrader writes; So I was sitting here thinking to myself “This is Friday and I’m not getting much of anything done. Maybe I should write another Friday Framework Highlight.” I figured that it was a good idea so I pondered what I should write. I came up blank and so I asked Matthew Weier O’Phinney. “Multiple writers for Zend_Log,” he said. I agreed.

If you were not aware, Zend_Log provides facilities for writing to multiple logs through the same log instance. Additionally, you can do this via configuration options when using a Zend_Applicatin resource plugin. Together those make for very powerful logging mechanisms. “How?” you ask? It’s really easy. Take your application.ini file, which you use to configure your Zend_Application instance, and make it look something like this. I’ll highlight the pertinent parts

What this does is say that “in production, log warnings and above to the log file, but in development, log debug to the log file AND send the log items to FirePHP.” Then, in our index controller we put this:

In production we wouldn’t get anything since this code would filter out debug logging, due to the resources.log.stream.filterParams.priority setting in the production section in application.ini. Simple. Done.