On this page



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');

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

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

// 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.