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-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
23 /** Zend_Log_Formatter_Interface */
24 require_once 'Zend/Log/Formatter/Interface.php';
29 * @subpackage Formatter
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
34 class Zend_Log_Formatter_Simple
implements Zend_Log_Formatter_Interface
41 const DEFAULT_FORMAT
= '%timestamp% %priorityName% (%priority%): %message%';
46 * @param null|string $format Format specifier for log messages
47 * @throws Zend_Log_Exception
49 public function __construct($format = null)
51 if ($format === null) {
52 $format = self
::DEFAULT_FORMAT
. PHP_EOL
;
55 if (! is_string($format)) {
56 require_once 'Zend/Log/Exception.php';
57 throw new Zend_Log_Exception('Format must be a string');
60 $this->_format
= $format;
64 * Formats data into a single line to be written by the writer.
66 * @param array $event event data
67 * @return string formatted line to write to the log
69 public function format($event)
71 $output = $this->_format
;
72 foreach ($event as $name => $value) {
74 if ((is_object($value) && !method_exists($value,'__toString'))
75 ||
is_array($value)) {
77 $value = gettype($value);
80 $output = str_replace("%$name%", $value, $output);