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 Handlers
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 Handlers
24: */
25: abstract class Horde_Log_Handler_Base
26: {
27: /**
28: * Options.
29: *
30: * @var array
31: */
32: protected $_options = array(
33: 'ident' => ''
34: );
35:
36: /**
37: * List of filter objects.
38: *
39: * @var array
40: */
41: protected $_filters = array();
42:
43: /**
44: * Add a filter specific to this handler.
45: *
46: * @param Horde_Log_Filter $filter Filter to add.
47: */
48: public function addFilter($filter)
49: {
50: $this->_filters[] = is_integer($filter)
51: ? new Horde_Log_Filter_Level($filter)
52: : $filter;
53: }
54:
55: /**
56: * Log a message to this handler.
57: *
58: * @param array $event Log event.
59: */
60: public function log($event)
61: {
62: // If any local filter rejects the message, don't log it.
63: foreach ($this->_filters as $filter) {
64: if (!$filter->accept($event)) {
65: return;
66: }
67: }
68:
69: $this->write($event);
70: }
71:
72: /**
73: * Sets an option specific to the implementation of the log handler.
74: *
75: * @param string $optionKey Key name for the option to be changed. Keys
76: * are handler-specific.
77: * @param mixed $optionValue New value to assign to the option
78: *
79: * @return boolean True.
80: * @throws Horde_Log_Exception
81: */
82: public function setOption($optionKey, $optionValue)
83: {
84: if (!isset($this->_options[$optionKey])) {
85: throw new Horde_Log_Exception('Unknown option "' . $optionKey . '".');
86: }
87: $this->_options[$optionKey] = $optionValue;
88:
89: return true;
90: }
91:
92: /**
93: * Buffer a message to be stored in the storage.
94: *
95: * @param array $event Log event.
96: */
97: abstract public function write($event);
98:
99: }
100: