13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Log |
16 * @package Zend_Log |
17 * @subpackage Formatter |
17 * @subpackage Formatter |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: Simple.php 20096 2010-01-06 02:05:09Z bkarwin $ |
20 * @version $Id: Simple.php 24593 2012-01-05 20:35:02Z matthew $ |
21 */ |
21 */ |
22 |
22 |
23 /** Zend_Log_Formatter_Interface */ |
23 /** Zend_Log_Formatter_Abstract */ |
24 require_once 'Zend/Log/Formatter/Interface.php'; |
24 require_once 'Zend/Log/Formatter/Abstract.php'; |
25 |
25 |
26 /** |
26 /** |
27 * @category Zend |
27 * @category Zend |
28 * @package Zend_Log |
28 * @package Zend_Log |
29 * @subpackage Formatter |
29 * @subpackage Formatter |
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
30 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
31 * @license http://framework.zend.com/license/new-bsd New BSD License |
31 * @license http://framework.zend.com/license/new-bsd New BSD License |
32 * @version $Id: Simple.php 20096 2010-01-06 02:05:09Z bkarwin $ |
32 * @version $Id: Simple.php 24593 2012-01-05 20:35:02Z matthew $ |
33 */ |
33 */ |
34 class Zend_Log_Formatter_Simple implements Zend_Log_Formatter_Interface |
34 class Zend_Log_Formatter_Simple extends Zend_Log_Formatter_Abstract |
35 { |
35 { |
36 /** |
36 /** |
37 * @var string |
37 * @var string |
38 */ |
38 */ |
39 protected $_format; |
39 protected $_format; |
42 |
42 |
43 /** |
43 /** |
44 * Class constructor |
44 * Class constructor |
45 * |
45 * |
46 * @param null|string $format Format specifier for log messages |
46 * @param null|string $format Format specifier for log messages |
|
47 * @return void |
47 * @throws Zend_Log_Exception |
48 * @throws Zend_Log_Exception |
48 */ |
49 */ |
49 public function __construct($format = null) |
50 public function __construct($format = null) |
50 { |
51 { |
51 if ($format === null) { |
52 if ($format === null) { |
52 $format = self::DEFAULT_FORMAT . PHP_EOL; |
53 $format = self::DEFAULT_FORMAT . PHP_EOL; |
53 } |
54 } |
54 |
55 |
55 if (! is_string($format)) { |
56 if (!is_string($format)) { |
56 require_once 'Zend/Log/Exception.php'; |
57 require_once 'Zend/Log/Exception.php'; |
57 throw new Zend_Log_Exception('Format must be a string'); |
58 throw new Zend_Log_Exception('Format must be a string'); |
58 } |
59 } |
59 |
60 |
60 $this->_format = $format; |
61 $this->_format = $format; |
|
62 } |
|
63 |
|
64 /** |
|
65 * Factory for Zend_Log_Formatter_Simple classe |
|
66 * |
|
67 * @param array|Zend_Config $options |
|
68 * @return Zend_Log_Formatter_Simple |
|
69 */ |
|
70 public static function factory($options) |
|
71 { |
|
72 $format = null; |
|
73 if (null !== $options) { |
|
74 if ($options instanceof Zend_Config) { |
|
75 $options = $options->toArray(); |
|
76 } |
|
77 |
|
78 if (array_key_exists('format', $options)) { |
|
79 $format = $options['format']; |
|
80 } |
|
81 } |
|
82 |
|
83 return new self($format); |
61 } |
84 } |
62 |
85 |
63 /** |
86 /** |
64 * Formats data into a single line to be written by the writer. |
87 * Formats data into a single line to be written by the writer. |
65 * |
88 * |
67 * @return string formatted line to write to the log |
90 * @return string formatted line to write to the log |
68 */ |
91 */ |
69 public function format($event) |
92 public function format($event) |
70 { |
93 { |
71 $output = $this->_format; |
94 $output = $this->_format; |
|
95 |
72 foreach ($event as $name => $value) { |
96 foreach ($event as $name => $value) { |
73 |
|
74 if ((is_object($value) && !method_exists($value,'__toString')) |
97 if ((is_object($value) && !method_exists($value,'__toString')) |
75 || is_array($value)) { |
98 || is_array($value) |
76 |
99 ) { |
77 $value = gettype($value); |
100 $value = gettype($value); |
78 } |
101 } |
79 |
102 |
80 $output = str_replace("%$name%", $value, $output); |
103 $output = str_replace("%$name%", $value, $output); |
81 } |
104 } |
|
105 |
82 return $output; |
106 return $output; |
83 } |
107 } |
84 |
|
85 } |
108 } |