On this page

Reference

Filters

A filter prevents a message from being written to the log.

You can add a filter to a specific writer using the addFilter() method of the writer:

use Laminas\Log\Logger;

$logger = new Logger();

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

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

// add a filter only to writer2
$filter = new Laminas\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

Filter Class Short Name Description
Laminas\Log\Filter\Priority Priority Filter logging by $priority. By default, it will accept any log event whose priority value is less than or equal to $priority.
Laminas\Log\Filter\Regex Regex Filter out any log messages not matching the regex pattern. This filter uses the preg_match() function.
Laminas\Log\Filter\Timestamp Timestamp Filters log events based on the time when they were triggered. It can be configured by specifying either idate()-compliant format characters along with the desired value, or a full DateTime instance. An appropriate comparison operator must be supplied in either case.
Laminas\Log\Filter\SuppressFilter SuppressFilter A simple boolean filter; a boolean true value passed to the constructor suppresses all log events, while a boolean false value accepts all log events.
Laminas\Log\Filter\Validator Validator Filter any log messages that fail validaton by the composed Laminas\Validator\ValidatorInterface implementation.

Found a mistake or want to contribute to the documentation? Edit this page on GitHub!