PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Zend/Log/Writer/Firebug.php

https://bitbucket.org/sunil_nextbits/magento2
PHP | 201 lines | 79 code | 22 blank | 100 comment | 7 complexity | 4eefc2805b939c1518be4de83ede0216 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-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. /** 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-2010 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. * @var array
  44. */
  45. protected $_priorityStyles = array(Zend_Log::EMERG => Zend_Wildfire_Plugin_FirePhp::ERROR,
  46. Zend_Log::ALERT => Zend_Wildfire_Plugin_FirePhp::ERROR,
  47. Zend_Log::CRIT => Zend_Wildfire_Plugin_FirePhp::ERROR,
  48. Zend_Log::ERR => Zend_Wildfire_Plugin_FirePhp::ERROR,
  49. Zend_Log::WARN => Zend_Wildfire_Plugin_FirePhp::WARN,
  50. Zend_Log::NOTICE => Zend_Wildfire_Plugin_FirePhp::INFO,
  51. Zend_Log::INFO => Zend_Wildfire_Plugin_FirePhp::INFO,
  52. Zend_Log::DEBUG => Zend_Wildfire_Plugin_FirePhp::LOG);
  53. /**
  54. * The default logging style for un-mapped priorities
  55. * @var string
  56. */
  57. protected $_defaultPriorityStyle = Zend_Wildfire_Plugin_FirePhp::LOG;
  58. /**
  59. * Flag indicating whether the log writer is enabled
  60. * @var boolean
  61. */
  62. protected $_enabled = true;
  63. /**
  64. * Class constructor
  65. */
  66. public function __construct()
  67. {
  68. if (php_sapi_name() == 'cli') {
  69. $this->setEnabled(false);
  70. }
  71. $this->_formatter = new Zend_Log_Formatter_Firebug();
  72. }
  73. /**
  74. * Create a new instance of Zend_Log_Writer_Firebug
  75. *
  76. * @param array|Zend_Config $config
  77. * @return Zend_Log_Writer_Firebug
  78. * @throws Zend_Log_Exception
  79. */
  80. static public function factory($config)
  81. {
  82. return new self();
  83. }
  84. /**
  85. * Enable or disable the log writer.
  86. *
  87. * @param boolean $enabled Set to TRUE to enable the log writer
  88. * @return boolean The previous value.
  89. */
  90. public function setEnabled($enabled)
  91. {
  92. $previous = $this->_enabled;
  93. $this->_enabled = $enabled;
  94. return $previous;
  95. }
  96. /**
  97. * Determine if the log writer is enabled.
  98. *
  99. * @return boolean Returns TRUE if the log writer is enabled.
  100. */
  101. public function getEnabled()
  102. {
  103. return $this->_enabled;
  104. }
  105. /**
  106. * Set the default display style for user-defined priorities
  107. *
  108. * @param string $style The default log display style
  109. * @return string Returns previous default log display style
  110. */
  111. public function setDefaultPriorityStyle($style)
  112. {
  113. $previous = $this->_defaultPriorityStyle;
  114. $this->_defaultPriorityStyle = $style;
  115. return $previous;
  116. }
  117. /**
  118. * Get the default display style for user-defined priorities
  119. *
  120. * @return string Returns the default log display style
  121. */
  122. public function getDefaultPriorityStyle()
  123. {
  124. return $this->_defaultPriorityStyle;
  125. }
  126. /**
  127. * Set a display style for a logging priority
  128. *
  129. * @param int $priority The logging priority
  130. * @param string $style The logging display style
  131. * @return string|boolean The previous logging display style if defined or TRUE otherwise
  132. */
  133. public function setPriorityStyle($priority, $style)
  134. {
  135. $previous = true;
  136. if (array_key_exists($priority,$this->_priorityStyles)) {
  137. $previous = $this->_priorityStyles[$priority];
  138. }
  139. $this->_priorityStyles[$priority] = $style;
  140. return $previous;
  141. }
  142. /**
  143. * Get a display style for a logging priority
  144. *
  145. * @param int $priority The logging priority
  146. * @return string|boolean The logging display style if defined or FALSE otherwise
  147. */
  148. public function getPriorityStyle($priority)
  149. {
  150. if (array_key_exists($priority,$this->_priorityStyles)) {
  151. return $this->_priorityStyles[$priority];
  152. }
  153. return false;
  154. }
  155. /**
  156. * Log a message to the Firebug Console.
  157. *
  158. * @param array $event The event data
  159. * @return void
  160. */
  161. protected function _write($event)
  162. {
  163. if (!$this->getEnabled()) {
  164. return;
  165. }
  166. if (array_key_exists($event['priority'],$this->_priorityStyles)) {
  167. $type = $this->_priorityStyles[$event['priority']];
  168. } else {
  169. $type = $this->_defaultPriorityStyle;
  170. }
  171. $message = $this->_formatter->format($event);
  172. $label = isset($event['firebugLabel'])?$event['firebugLabel']:null;
  173. Zend_Wildfire_Plugin_FirePhp::getInstance()->send($message,
  174. $label,
  175. $type,
  176. array('traceOffset'=>4,
  177. 'fixZendLogOffsetIfApplicable'=>true));
  178. }
  179. }