Formatters | Zend_Log Programmer's Reference Guide | Using the Factory to Create a Log

# Filters

A Filter object blocks a message from being written to the log.

# Filtering for All Writers

To filter before all writers, you can add any number of Filters to a Log object using the addFilter() method:

1. $logger = new Zend_Log();
3. $writer = new Zend_Log_Writer_Stream('php://output');
4. $logger->addWriter($writer);
6. $filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
7. $logger->addFilter($filter);
9. // blocked
10. $logger->info('Informational message');
12. // logged
13. $logger->emerg('Emergency message');

When you add one or more Filters to the Log object, the message must pass through all of the Filters before any Writers receives it.

# Filtering for a Writer Instance

To filter only on a specific Writer instance, use the addFilter() method of that Writer:

1. $logger = new Zend_Log();
3. $writer1 = new Zend_Log_Writer_Stream('/path/to/first/logfile');
4. $logger->addWriter($writer1);
6. $writer2 = new Zend_Log_Writer_Stream('/path/to/second/logfile');
7. $logger->addWriter($writer2);
9. // add a filter only to writer2
10. $filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
11. $writer2->addFilter($filter);
13. // logged to writer1, blocked from writer2
14. $logger->info('Informational message');
16. // logged by both writers
17. $logger->emerg('Emergency message');

Formatters | Zend_Log Programmer's Reference Guide | Using the Factory to Create a Log