[ZF-10089] Zend_Log
[zend/radio.git] / library / Zend / Log / Formatter / Simple.php
blob790f520b8990be72faa3353d8cb1d1a9c037a593
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Log
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
20 * @version $Id$
23 /** Zend_Log_Formatter_Interface */
24 require_once 'Zend/Log/Formatter/Interface.php';
26 /**
27 * @category Zend
28 * @package Zend_Log
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
32 * @version $Id$
34 class Zend_Log_Formatter_Simple implements Zend_Log_Formatter_Interface
36 /**
37 * @var string
39 protected $_format;
41 const DEFAULT_FORMAT = '%timestamp% %priorityName% (%priority%): %message%';
43 /**
44 * Class constructor
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;
63 /**
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);
82 return $output;