1: <?php
2: /**
3: * Horde Log package
4: *
5: * This package is based on Zend_Log from the Zend Framework
6: * (http://framework.zend.com). Both that package and this
7: * one were written by Mike Naberezny and Chuck Hagenbuch.
8: *
9: * @author Mike Naberezny <mike@maintainable.com>
10: * @author Chuck Hagenbuch <chuck@horde.org>
11: * @category Horde
12: * @license http://www.horde.org/licenses/bsd BSD
13: * @package Log
14: * @subpackage Filters
15: */
16:
17: /**
18: * @author Mike Naberezny <mike@maintainable.com>
19: * @author Chuck Hagenbuch <chuck@horde.org>
20: * @category Horde
21: * @license http://www.horde.org/licenses/bsd BSD
22: * @package Log
23: * @subpackage Filters
24: */
25: class Horde_Log_Filter_Message implements Horde_Log_Filter
26: {
27: /**
28: * Filter regex.
29: *
30: * @var string
31: */
32: protected $_regexp;
33:
34: /**
35: * Filter out any log messages not matching $regexp.
36: *
37: * @param string $regexp Regular expression to test the log message.
38: *
39: * @throws InvalidArgumentException Invalid regular expression.
40: */
41: public function __construct($regexp)
42: {
43: if (@preg_match($regexp, '') === false) {
44: throw new InvalidArgumentException('Invalid regular expression ' . $regexp);
45: }
46:
47: $this->_regexp = $regexp;
48: }
49:
50: /**
51: * Returns Horde_Log_Filter::ACCEPT to accept the message,
52: * Horde_Log_Filter::IGNORE to ignore it.
53: *
54: * @param array $event Log event.
55: *
56: * @return boolean Accepted?
57: */
58: public function accept($event)
59: {
60: return (preg_match($this->_regexp, $event['message']) > 0);
61: }
62:
63: }
64: