PageRenderTime 35ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/system/libraries/Zend/Log/Writer/Firebug.php

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