[ZF-10089] Zend_Log
[zend/radio.git] / library / Zend / Log / Writer / Firebug.php
blob457c61514a5e92236b67f2784d01de90d4bb8d42
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 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$
23 /** Zend_Log */
24 require_once 'Zend/Log.php';
26 /** Zend_Log_Writer_Abstract */
27 require_once 'Zend/Log/Writer/Abstract.php';
29 /** Zend_Log_Formatter_Firebug */
30 require_once 'Zend/Log/Formatter/Firebug.php';
32 /** Zend_Wildfire_Plugin_FirePhp */
33 require_once 'Zend/Wildfire/Plugin/FirePhp.php';
35 /**
36 * Writes log messages to the Firebug Console via FirePHP.
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
44 class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract
47 /**
48 * Maps logging priorities to logging display styles
49 * @var array
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);
60 /**
61 * The default logging style for un-mapped priorities
62 * @var string
64 protected $_defaultPriorityStyle = Zend_Wildfire_Plugin_FirePhp::LOG;
66 /**
67 * Flag indicating whether the log writer is enabled
68 * @var boolean
70 protected $_enabled = true;
72 /**
73 * Class constructor
75 public function __construct()
77 if (php_sapi_name() == 'cli') {
78 $this->setEnabled(false);
81 $this->_formatter = new Zend_Log_Formatter_Firebug();
84 /**
85 * Create a new instance of Zend_Log_Writer_Firebug
87 * @param array|Zend_Config $config
88 * @return Zend_Log_Writer_Firebug
89 * @throws Zend_Log_Exception
91 static public function factory($config)
93 return new self();
96 /**
97 * Enable or disable the log writer.
99 * @param boolean $enabled Set to TRUE to enable the log writer
100 * @return boolean The previous value.
102 public function setEnabled($enabled)
104 $previous = $this->_enabled;
105 $this->_enabled = $enabled;
106 return $previous;
110 * Determine if the log writer is enabled.
112 * @return boolean Returns TRUE if the log writer is enabled.
114 public function getEnabled()
116 return $this->_enabled;
120 * Set the default display style for user-defined priorities
122 * @param string $style The default log display style
123 * @return string Returns previous default log display style
125 public function setDefaultPriorityStyle($style)
127 $previous = $this->_defaultPriorityStyle;
128 $this->_defaultPriorityStyle = $style;
129 return $previous;
133 * Get the default display style for user-defined priorities
135 * @return string Returns the default log display style
137 public function getDefaultPriorityStyle()
139 return $this->_defaultPriorityStyle;
143 * Set a display style for a logging priority
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
149 public function setPriorityStyle($priority, $style)
151 $previous = true;
152 if (array_key_exists($priority,$this->_priorityStyles)) {
153 $previous = $this->_priorityStyles[$priority];
155 $this->_priorityStyles[$priority] = $style;
156 return $previous;
160 * Get a display style for a logging priority
162 * @param int $priority The logging priority
163 * @return string|boolean The logging display style if defined or FALSE otherwise
165 public function getPriorityStyle($priority)
167 if (array_key_exists($priority,$this->_priorityStyles)) {
168 return $this->_priorityStyles[$priority];
170 return false;
174 * Log a message to the Firebug Console.
176 * @param array $event The event data
177 * @return void
179 protected function _write($event)
181 if (!$this->getEnabled()) {
182 return;
185 if (array_key_exists($event['priority'],$this->_priorityStyles)) {
186 $type = $this->_priorityStyles[$event['priority']];
187 } else {
188 $type = $this->_defaultPriorityStyle;
191 $message = $this->_formatter->format($event);
193 $label = isset($event['firebugLabel'])?$event['firebugLabel']:null;
195 Zend_Wildfire_Plugin_FirePhp::getInstance()->send($message,
196 $label,
197 $type,
198 array('traceOffset'=>6));