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.
17
* @subpackage Formatter
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
20
* @version $Id: Simple.php 10725 2008-08-06 16:01:05Z cadorn $
23
/** Zend_Log_Formatter_Interface */
24
require_once 'Zend/Log/Formatter/Interface.php';
26
/** Zend_Log_Exception */
27
require_once 'Zend/Log/Exception.php';
32
* @subpackage Formatter
33
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
34
* @license http://framework.zend.com/license/new-bsd New BSD License
35
* @version $Id: Simple.php 10725 2008-08-06 16:01:05Z cadorn $
37
class Zend_Log_Formatter_Simple implements Zend_Log_Formatter_Interface
44
const DEFAULT_FORMAT = '%timestamp% %priorityName% (%priority%): %message%';
49
* @param null|string $format Format specifier for log messages
50
* @throws Zend_Log_Exception
52
public function __construct($format = null)
54
if ($format === null) {
55
$format = self::DEFAULT_FORMAT . PHP_EOL;
58
if (! is_string($format)) {
59
throw new Zend_Log_Exception('Format must be a string');
62
$this->_format = $format;
66
* Formats data into a single line to be written by the writer.
68
* @param array $event event data
69
* @return string formatted line to write to the log
71
public function format($event)
73
$output = $this->_format;
74
foreach ($event as $name => $value) {
76
if ((is_object($value) && !method_exists($value,'__toString'))
77
|| is_array($value)) {
79
$value = gettype($value);
82
$output = str_replace("%$name%", $value, $output);