|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
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. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Log |
|
17 * @subpackage Writer |
|
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: Firebug.php 23066 2010-10-09 23:29:20Z cadorn $ |
|
21 */ |
|
22 |
|
23 /** Zend_Log */ |
|
24 require_once 'Zend/Log.php'; |
|
25 |
|
26 /** Zend_Log_Writer_Abstract */ |
|
27 require_once 'Zend/Log/Writer/Abstract.php'; |
|
28 |
|
29 /** Zend_Log_Formatter_Firebug */ |
|
30 require_once 'Zend/Log/Formatter/Firebug.php'; |
|
31 |
|
32 /** Zend_Wildfire_Plugin_FirePhp */ |
|
33 require_once 'Zend/Wildfire/Plugin/FirePhp.php'; |
|
34 |
|
35 /** |
|
36 * Writes log messages to the Firebug Console via FirePHP. |
|
37 * |
|
38 * @category Zend |
|
39 * @package Zend_Log |
|
40 * @subpackage Writer |
|
41 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
42 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
43 */ |
|
44 class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract |
|
45 { |
|
46 |
|
47 /** |
|
48 * Maps logging priorities to logging display styles |
|
49 * @var array |
|
50 */ |
|
51 protected $_priorityStyles = array(Zend_Log::EMERG => Zend_Wildfire_Plugin_FirePhp::ERROR, |
|
52 Zend_Log::ALERT => Zend_Wildfire_Plugin_FirePhp::ERROR, |
|
53 Zend_Log::CRIT => Zend_Wildfire_Plugin_FirePhp::ERROR, |
|
54 Zend_Log::ERR => Zend_Wildfire_Plugin_FirePhp::ERROR, |
|
55 Zend_Log::WARN => Zend_Wildfire_Plugin_FirePhp::WARN, |
|
56 Zend_Log::NOTICE => Zend_Wildfire_Plugin_FirePhp::INFO, |
|
57 Zend_Log::INFO => Zend_Wildfire_Plugin_FirePhp::INFO, |
|
58 Zend_Log::DEBUG => Zend_Wildfire_Plugin_FirePhp::LOG); |
|
59 |
|
60 /** |
|
61 * The default logging style for un-mapped priorities |
|
62 * @var string |
|
63 */ |
|
64 protected $_defaultPriorityStyle = Zend_Wildfire_Plugin_FirePhp::LOG; |
|
65 |
|
66 /** |
|
67 * Flag indicating whether the log writer is enabled |
|
68 * @var boolean |
|
69 */ |
|
70 protected $_enabled = true; |
|
71 |
|
72 /** |
|
73 * Class constructor |
|
74 */ |
|
75 public function __construct() |
|
76 { |
|
77 if (php_sapi_name() == 'cli') { |
|
78 $this->setEnabled(false); |
|
79 } |
|
80 |
|
81 $this->_formatter = new Zend_Log_Formatter_Firebug(); |
|
82 } |
|
83 |
|
84 /** |
|
85 * Create a new instance of Zend_Log_Writer_Firebug |
|
86 * |
|
87 * @param array|Zend_Config $config |
|
88 * @return Zend_Log_Writer_Firebug |
|
89 * @throws Zend_Log_Exception |
|
90 */ |
|
91 static public function factory($config) |
|
92 { |
|
93 return new self(); |
|
94 } |
|
95 |
|
96 /** |
|
97 * Enable or disable the log writer. |
|
98 * |
|
99 * @param boolean $enabled Set to TRUE to enable the log writer |
|
100 * @return boolean The previous value. |
|
101 */ |
|
102 public function setEnabled($enabled) |
|
103 { |
|
104 $previous = $this->_enabled; |
|
105 $this->_enabled = $enabled; |
|
106 return $previous; |
|
107 } |
|
108 |
|
109 /** |
|
110 * Determine if the log writer is enabled. |
|
111 * |
|
112 * @return boolean Returns TRUE if the log writer is enabled. |
|
113 */ |
|
114 public function getEnabled() |
|
115 { |
|
116 return $this->_enabled; |
|
117 } |
|
118 |
|
119 /** |
|
120 * Set the default display style for user-defined priorities |
|
121 * |
|
122 * @param string $style The default log display style |
|
123 * @return string Returns previous default log display style |
|
124 */ |
|
125 public function setDefaultPriorityStyle($style) |
|
126 { |
|
127 $previous = $this->_defaultPriorityStyle; |
|
128 $this->_defaultPriorityStyle = $style; |
|
129 return $previous; |
|
130 } |
|
131 |
|
132 /** |
|
133 * Get the default display style for user-defined priorities |
|
134 * |
|
135 * @return string Returns the default log display style |
|
136 */ |
|
137 public function getDefaultPriorityStyle() |
|
138 { |
|
139 return $this->_defaultPriorityStyle; |
|
140 } |
|
141 |
|
142 /** |
|
143 * Set a display style for a logging priority |
|
144 * |
|
145 * @param int $priority The logging priority |
|
146 * @param string $style The logging display style |
|
147 * @return string|boolean The previous logging display style if defined or TRUE otherwise |
|
148 */ |
|
149 public function setPriorityStyle($priority, $style) |
|
150 { |
|
151 $previous = true; |
|
152 if (array_key_exists($priority,$this->_priorityStyles)) { |
|
153 $previous = $this->_priorityStyles[$priority]; |
|
154 } |
|
155 $this->_priorityStyles[$priority] = $style; |
|
156 return $previous; |
|
157 } |
|
158 |
|
159 /** |
|
160 * Get a display style for a logging priority |
|
161 * |
|
162 * @param int $priority The logging priority |
|
163 * @return string|boolean The logging display style if defined or FALSE otherwise |
|
164 */ |
|
165 public function getPriorityStyle($priority) |
|
166 { |
|
167 if (array_key_exists($priority,$this->_priorityStyles)) { |
|
168 return $this->_priorityStyles[$priority]; |
|
169 } |
|
170 return false; |
|
171 } |
|
172 |
|
173 /** |
|
174 * Log a message to the Firebug Console. |
|
175 * |
|
176 * @param array $event The event data |
|
177 * @return void |
|
178 */ |
|
179 protected function _write($event) |
|
180 { |
|
181 if (!$this->getEnabled()) { |
|
182 return; |
|
183 } |
|
184 |
|
185 if (array_key_exists($event['priority'],$this->_priorityStyles)) { |
|
186 $type = $this->_priorityStyles[$event['priority']]; |
|
187 } else { |
|
188 $type = $this->_defaultPriorityStyle; |
|
189 } |
|
190 |
|
191 $message = $this->_formatter->format($event); |
|
192 |
|
193 $label = isset($event['firebugLabel'])?$event['firebugLabel']:null; |
|
194 |
|
195 Zend_Wildfire_Plugin_FirePhp::getInstance()->send($message, |
|
196 $label, |
|
197 $type, |
|
198 array('traceOffset'=>4, |
|
199 'fixZendLogOffsetIfApplicable'=>true)); |
|
200 } |
|
201 } |