[ZF-10089] Zend_Log
[zend/radio.git] / library / Zend / Log / Writer / Abstract.php
blob41c057b8fc18df7ac0b0223ea3221dbfb639c0fe
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Log
17 * @subpackage Writer
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
20 * @version $Id$
23 /** Zend_Log_Filter_Priority */
24 require_once 'Zend/Log/Filter/Priority.php';
26 /**
27 * @category Zend
28 * @package Zend_Log
29 * @subpackage Writer
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
32 * @version $Id$
34 abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface
36 /**
37 * @var array of Zend_Log_Filter_Interface
39 protected $_filters = array();
41 /**
42 * Formats the log message before writing.
43 * @var Zend_Log_Formatter_Interface
45 protected $_formatter;
47 /**
48 * Add a filter specific to this writer.
50 * @param Zend_Log_Filter_Interface $filter
51 * @return void
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;
68 /**
69 * Log a message to this writer.
71 * @param array $event log data event
72 * @return void
74 public function write($event)
76 foreach ($this->_filters as $filter) {
77 if (! $filter->accept($event)) {
78 return;
82 // exception occurs on error
83 $this->_write($event);
86 /**
87 * Set a new formatter for this writer
89 * @param Zend_Log_Formatter_Interface $formatter
90 * @return void
92 public function setFormatter(Zend_Log_Formatter_Interface $formatter)
94 $this->_formatter = $formatter;
97 /**
98 * Perform shutdown activites such as closing open resources
100 * @return void
102 public function shutdown()
106 * Write a message to the log.
108 * @param array $event log data event
109 * @return void
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
117 * @return 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'
133 return $config;