The filter admits two options {@link $stringToMatch} and * {@link $acceptOnMatch}. If there is a match (using {@link PHP_MANUAL#strpos} * between the value of the {@link $stringToMatch} option and the message * of the {@link LoggerLoggingEvent}, * then the {@link decide()} method returns {@link LoggerFilter::ACCEPT} if * the AcceptOnMatch option value is true, if it is false then * {@link LoggerFilter::DENY} is returned. If there is no match, {@link LoggerFilter::NEUTRAL} * is returned.
* ** An example for this filter: * * {@example ../../examples/php/filter_stringmatch.php 19} * *
* The corresponding XML file: * * {@example ../../examples/resources/filter_stringmatch.xml 18} * * @version $Revision: 883108 $ * @package log4php * @subpackage filters * @since 0.3 */ class LoggerFilterStringMatch extends LoggerFilter { /** * @var boolean */ private $acceptOnMatch = true; /** * @var string */ private $stringToMatch = null; /** * @param mixed $acceptOnMatch a boolean or a string ('true' or 'false') */ public function setAcceptOnMatch($acceptOnMatch) { $this->acceptOnMatch = is_bool($acceptOnMatch) ? $acceptOnMatch : (bool)(strtolower($acceptOnMatch) == 'true'); } /** * @param string $s the string to match */ public function setStringToMatch($s) { $this->stringToMatch = $s; } /** * @return integer a {@link LOGGER_FILTER_NEUTRAL} is there is no string match. */ public function decide(LoggerLoggingEvent $event) { $msg = $event->getRenderedMessage(); if($msg === null or $this->stringToMatch === null) { return LoggerFilter::NEUTRAL; } if(strpos($msg, $this->stringToMatch) !== false ) { return ($this->acceptOnMatch) ? LoggerFilter::ACCEPT : LoggerFilter::DENY; } return LoggerFilter::NEUTRAL; } }