7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
23 /** Zend_Log_Filter_Priority */
24 require_once 'Zend/Log/Filter/Priority.php';
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
34 abstract class Zend_Log_Writer_Abstract
implements Zend_Log_FactoryInterface
37 * @var array of Zend_Log_Filter_Interface
39 protected $_filters = array();
42 * Formats the log message before writing.
43 * @var Zend_Log_Formatter_Interface
45 protected $_formatter;
48 * Add a filter specific to this writer.
50 * @param Zend_Log_Filter_Interface $filter
53 public function addFilter($filter)
55 if (is_integer($filter)) {
56 $filter = new Zend_Log_Filter_Priority($filter);
59 if (!$filter instanceof Zend_Log_Filter_Interface
) {
60 /** @see Zend_Log_Exception */
61 require_once 'Zend/Log/Exception.php';
62 throw new Zend_Log_Exception('Invalid filter provided');
65 $this->_filters
[] = $filter;
69 * Log a message to this writer.
71 * @param array $event log data event
74 public function write($event)
76 foreach ($this->_filters
as $filter) {
77 if (! $filter->accept($event)) {
82 // exception occurs on error
83 $this->_write($event);
87 * Set a new formatter for this writer
89 * @param Zend_Log_Formatter_Interface $formatter
92 public function setFormatter(Zend_Log_Formatter_Interface
$formatter)
94 $this->_formatter
= $formatter;
98 * Perform shutdown activites such as closing open resources
102 public function shutdown()
106 * Write a message to the log.
108 * @param array $event log data event
111 abstract protected function _write($event);
114 * Validate and optionally convert the config to array
116 * @param array|Zend_Config $config Zend_Config or Array
118 * @throws Zend_Log_Exception
120 static protected function _parseConfig($config)
122 if ($config instanceof Zend_Config
) {
123 $config = $config->toArray();
126 if (!is_array($config)) {
127 require_once 'Zend/Log/Exception.php';
128 throw new Zend_Log_Exception(
129 'Configuration must be an array or instance of Zend_Config'