2009-11-21 03:32:24 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Zend Framework
|
|
|
|
*
|
|
|
|
* LICENSE
|
|
|
|
*
|
|
|
|
* This source file is subject to the new BSD license that is bundled
|
|
|
|
* with this package in the file LICENSE.txt.
|
|
|
|
* It is also available through the world-wide-web at this URL:
|
|
|
|
* http://framework.zend.com/license/new-bsd
|
|
|
|
* If you did not receive a copy of the license and are unable to
|
|
|
|
* obtain it through the world-wide-web, please send an email
|
|
|
|
* to license@zend.com so we can send you a copy immediately.
|
|
|
|
*
|
|
|
|
* @category Zend
|
|
|
|
* @package Zend_Log
|
|
|
|
* @subpackage Writer
|
2011-05-30 11:30:04 +02:00
|
|
|
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
2009-11-21 03:32:24 +01:00
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
2011-05-30 11:30:04 +02:00
|
|
|
* @version $Id: Abstract.php 23775 2011-03-01 17:25:24Z ralph $
|
2009-11-21 03:32:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** Zend_Log_Filter_Priority */
|
|
|
|
require_once 'Zend/Log/Filter/Priority.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @category Zend
|
|
|
|
* @package Zend_Log
|
|
|
|
* @subpackage Writer
|
2011-05-30 11:30:04 +02:00
|
|
|
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
2009-11-21 03:32:24 +01:00
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
2011-05-30 11:30:04 +02:00
|
|
|
* @version $Id: Abstract.php 23775 2011-03-01 17:25:24Z ralph $
|
2009-11-21 03:32:24 +01:00
|
|
|
*/
|
2011-05-30 11:30:04 +02:00
|
|
|
abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface
|
2009-11-21 03:32:24 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array of Zend_Log_Filter_Interface
|
|
|
|
*/
|
|
|
|
protected $_filters = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats the log message before writing.
|
2011-05-30 11:30:04 +02:00
|
|
|
*
|
2009-11-21 03:32:24 +01:00
|
|
|
* @var Zend_Log_Formatter_Interface
|
|
|
|
*/
|
|
|
|
protected $_formatter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a filter specific to this writer.
|
|
|
|
*
|
|
|
|
* @param Zend_Log_Filter_Interface $filter
|
2011-05-30 11:30:04 +02:00
|
|
|
* @return Zend_Log_Writer_Abstract
|
2009-11-21 03:32:24 +01:00
|
|
|
*/
|
|
|
|
public function addFilter($filter)
|
|
|
|
{
|
2011-05-30 11:30:04 +02:00
|
|
|
if (is_int($filter)) {
|
2009-11-21 03:32:24 +01:00
|
|
|
$filter = new Zend_Log_Filter_Priority($filter);
|
|
|
|
}
|
|
|
|
|
2011-05-30 11:30:04 +02:00
|
|
|
if (!$filter instanceof Zend_Log_Filter_Interface) {
|
|
|
|
/** @see Zend_Log_Exception */
|
|
|
|
require_once 'Zend/Log/Exception.php';
|
|
|
|
throw new Zend_Log_Exception('Invalid filter provided');
|
|
|
|
}
|
|
|
|
|
2009-11-21 03:32:24 +01:00
|
|
|
$this->_filters[] = $filter;
|
2011-05-30 11:30:04 +02:00
|
|
|
return $this;
|
2009-11-21 03:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log a message to this writer.
|
|
|
|
*
|
2011-05-30 11:30:04 +02:00
|
|
|
* @param array $event log data event
|
2009-11-21 03:32:24 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function write($event)
|
|
|
|
{
|
|
|
|
foreach ($this->_filters as $filter) {
|
|
|
|
if (! $filter->accept($event)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// exception occurs on error
|
|
|
|
$this->_write($event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a new formatter for this writer
|
|
|
|
*
|
|
|
|
* @param Zend_Log_Formatter_Interface $formatter
|
2011-05-30 11:30:04 +02:00
|
|
|
* @return Zend_Log_Writer_Abstract
|
2009-11-21 03:32:24 +01:00
|
|
|
*/
|
2011-05-30 11:30:04 +02:00
|
|
|
public function setFormatter(Zend_Log_Formatter_Interface $formatter)
|
2009-11-21 03:32:24 +01:00
|
|
|
{
|
|
|
|
$this->_formatter = $formatter;
|
2011-05-30 11:30:04 +02:00
|
|
|
return $this;
|
2009-11-21 03:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform shutdown activites such as closing open resources
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function shutdown()
|
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a message to the log.
|
|
|
|
*
|
|
|
|
* @param array $event log data event
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
abstract protected function _write($event);
|
|
|
|
|
2011-05-30 11:30:04 +02:00
|
|
|
/**
|
|
|
|
* Validate and optionally convert the config to array
|
|
|
|
*
|
|
|
|
* @param array|Zend_Config $config Zend_Config or Array
|
|
|
|
* @return array
|
|
|
|
* @throws Zend_Log_Exception
|
|
|
|
*/
|
|
|
|
static protected function _parseConfig($config)
|
|
|
|
{
|
|
|
|
if ($config instanceof Zend_Config) {
|
|
|
|
$config = $config->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_array($config)) {
|
|
|
|
require_once 'Zend/Log/Exception.php';
|
|
|
|
throw new Zend_Log_Exception(
|
|
|
|
'Configuration must be an array or instance of Zend_Config'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
}
|