Filters

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

You can add a filter to a specific Writer using addFilter() method of that Writer:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
use Zend\Log\Logger;

$logger = new Logger();

$writer1 = new Zend\Log\Writer\Stream('/path/to/first/logfile');
$logger->addWriter($writer1);

$writer2 = new Zend\Log\Writer\Stream('/path/to/second/logfile');
$logger->addWriter($writer2);

// add a filter only to writer2
$filter = new Zend\Log\Filter\Priority(Logger::CRIT);
$writer2->addFilter($filter);

// logged to writer1, blocked from writer2
$logger->info('Informational message');

// logged by both writers
$logger->emerg('Emergency message');

Available filters

The Zend\Log\Filter available are:

  • Priority, filter logging by $priority. By default, it will accept any log event whose priority value is less than or equal to $priority.
  • Regex, filter out any log messages not matching the regex pattern. This filter use the preg_match() function of PHP.
  • SuppressFilter, this is a simple boolean filter. Call suppress(true) to suppress all log events. Call suppress(false) to accept all log events.
  • Validator, filter out any log messages not matching the Zend\Validator\Validator object passed to the filter.

Table Of Contents

Previous topic

Writers

Next topic

Formatters

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Filters on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.