--- Zend/Log.php 2010-04-29 12:38:18.709722300 -0400 +++ Zend/Log.php 2010-06-18 16:29:05.534421500 -0400 @@ -72,6 +72,12 @@ /** + * + * @var string + */ + protected $_defaultFormatterNamespace = 'Zend_Log_Formatter'; + + /** * Class constructor. Create a new logger * * @param Zend_Log_Writer_Abstract|null $writer default writer @@ -140,6 +146,11 @@ $writer->addFilter($filter); } + if (isset($config['formatterName'])) { + $formatter = $this->_constructFormatterFromConfig($config); + $writer->setFormatter($formatter); + } + return $writer; } @@ -163,7 +174,26 @@ } /** - * Construct a filter or writer from config + * Construct formatter object from configuration array or Zend_Config object + * + * @param array|Zend_Config $config Zend_Config or Array + * @return Zend_Log_Formatter_Interface + */ + protected function _constructFormatterFromConfig($config) + { + $formatter = $this->_constructFromConfig('formatter', $config, $this->_defaultFormatterNamespace); + + if (!$formatter instanceof Zend_Log_Formatter_Interface) { + /** @see Zend_Log_Exception */ + require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception("{$formatterName} does not implement Zend_Log_Formatter_Interface"); + } + + return $formatter; + } + + /** + * Construct a filter, formatter or writer from config * * @param string $type 'writer' of 'filter' * @param mixed $config Zend_Config or Array @@ -194,7 +224,7 @@ if (!$reflection->implementsInterface('Zend_Log_FactoryInterface')) { require_once 'Zend/Log/Exception.php'; throw new Zend_Log_Exception( - 'Driver does not implement Zend_Log_FactoryInterface and can not be constructed from config.' + "{$className} does not implement Zend_Log_FactoryInterface and can not be constructed from config." ); } --- Zend/Log/Formatter/Simple.php 2010-04-29 12:37:28.696122300 -0400 +++ Zend/Log/Formatter/Simple.php 2010-06-18 16:35:57.669490800 -0400 @@ -31,7 +31,8 @@ * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id: Simple.php 20096 2010-01-06 02:05:09Z bkarwin $ */ -class Zend_Log_Formatter_Simple implements Zend_Log_Formatter_Interface +class Zend_Log_Formatter_Simple extends Zend_Log_Formatter_Abstract + implements Zend_Log_Formatter_Interface { /** * @var string @@ -61,6 +62,24 @@ } /** + * Create a new instance of Zend_Log_Formatter_Simple + * + * @param array|Zend_Config $config + * @return Zend_Log_Formatter_Simple + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + $config = self::_parseConfig($config); + $config = array_merge(array( + 'format' => null + ), $config); + + return new self($config['format']); + } + + + /** * Formats data into a single line to be written by the writer. * * @param array $event event data --- Zend/Log/Formatter/Abstract.php 2010-06-18 14:58:32.595868200 -0400 +++ Zend/Log/Formatter/Abstract.php 2010-06-18 14:58:09.350868200 -0400 *************** --- 0 **** +++ 1,60 ---- + 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; + } + }