File indexing completed on 2024-12-22 05:36:50
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Log 0017 * @subpackage Formatter 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** Zend_Log_Formatter_Abstract */ 0024 // require_once 'Zend/Log/Formatter/Abstract.php'; 0025 0026 /** 0027 * @category Zend 0028 * @package Zend_Log 0029 * @subpackage Formatter 0030 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0031 * @license http://framework.zend.com/license/new-bsd New BSD License 0032 * @version $Id$ 0033 */ 0034 class Zend_Log_Formatter_Simple extends Zend_Log_Formatter_Abstract 0035 { 0036 /** 0037 * @var string 0038 */ 0039 protected $_format; 0040 0041 const DEFAULT_FORMAT = '%timestamp% %priorityName% (%priority%): %message%'; 0042 0043 /** 0044 * Class constructor 0045 * 0046 * @param null|string $format Format specifier for log messages 0047 * @return void 0048 * @throws Zend_Log_Exception 0049 */ 0050 public function __construct($format = null) 0051 { 0052 if ($format === null) { 0053 $format = self::DEFAULT_FORMAT . PHP_EOL; 0054 } 0055 0056 if (!is_string($format)) { 0057 // require_once 'Zend/Log/Exception.php'; 0058 throw new Zend_Log_Exception('Format must be a string'); 0059 } 0060 0061 $this->_format = $format; 0062 } 0063 0064 /** 0065 * Factory for Zend_Log_Formatter_Simple classe 0066 * 0067 * @param array|Zend_Config $options 0068 * @return Zend_Log_Formatter_Simple 0069 */ 0070 public static function factory($options) 0071 { 0072 $format = null; 0073 if (null !== $options) { 0074 if ($options instanceof Zend_Config) { 0075 $options = $options->toArray(); 0076 } 0077 0078 if (array_key_exists('format', $options)) { 0079 $format = $options['format']; 0080 } 0081 } 0082 0083 return new self($format); 0084 } 0085 0086 /** 0087 * Formats data into a single line to be written by the writer. 0088 * 0089 * @param array $event event data 0090 * @return string formatted line to write to the log 0091 */ 0092 public function format($event) 0093 { 0094 $output = $this->_format; 0095 0096 foreach ($event as $name => $value) { 0097 if ((is_object($value) && !method_exists($value,'__toString')) 0098 || is_array($value) 0099 ) { 0100 $value = gettype($value); 0101 } 0102 0103 $output = str_replace("%$name%", $value, $output); 0104 } 0105 0106 return $output; 0107 } 0108 }