PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Log/Writer/ZendMonitor.php

https://bitbucket.org/maatao/estrutura-b-sica-doctrine
PHP | 131 lines | 46 code | 10 blank | 75 comment | 7 complexity | d496f43ef9f7b9fb673aa48a4743d634 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: ZendMonitor.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /** Zend_Log_Writer_Abstract */
  23. require_once 'Zend/Log/Writer/Abstract.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Log
  27. * @subpackage Writer
  28. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @version $Id: ZendMonitor.php 23775 2011-03-01 17:25:24Z ralph $
  31. */
  32. class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract
  33. {
  34. /**
  35. * Is Zend Monitor enabled?
  36. *
  37. * @var boolean
  38. */
  39. protected $_isEnabled = true;
  40. /**
  41. * Is this for a Zend Server intance?
  42. *
  43. * @var boolean
  44. */
  45. protected $_isZendServer = false;
  46. /**
  47. * @return void
  48. */
  49. public function __construct()
  50. {
  51. if (!function_exists('monitor_custom_event')) {
  52. $this->_isEnabled = false;
  53. }
  54. if (function_exists('zend_monitor_custom_event')) {
  55. $this->_isZendServer = true;
  56. }
  57. }
  58. /**
  59. * Create a new instance of Zend_Log_Writer_ZendMonitor
  60. *
  61. * @param array|Zend_Config $config
  62. * @return Zend_Log_Writer_ZendMonitor
  63. */
  64. static public function factory($config)
  65. {
  66. return new self();
  67. }
  68. /**
  69. * Is logging to this writer enabled?
  70. *
  71. * If the Zend Monitor extension is not enabled, this log writer will
  72. * fail silently. You can query this method to determine if the log
  73. * writer is enabled.
  74. *
  75. * @return boolean
  76. */
  77. public function isEnabled()
  78. {
  79. return $this->_isEnabled;
  80. }
  81. /**
  82. * Log a message to this writer.
  83. *
  84. * @param array $event log data event
  85. * @return void
  86. */
  87. public function write($event)
  88. {
  89. if (!$this->isEnabled()) {
  90. return;
  91. }
  92. parent::write($event);
  93. }
  94. /**
  95. * Write a message to the log.
  96. *
  97. * @param array $event log data event
  98. * @return void
  99. */
  100. protected function _write($event)
  101. {
  102. $priority = $event['priority'];
  103. $message = $event['message'];
  104. unset($event['priority'], $event['message']);
  105. if (!empty($event)) {
  106. if ($this->_isZendServer) {
  107. // On Zend Server; third argument should be the event
  108. zend_monitor_custom_event($priority, $message, $event);
  109. } else {
  110. // On Zend Platform; third argument is severity -- either
  111. // 0 or 1 -- and fourth is optional (event)
  112. // Severity is either 0 (normal) or 1 (severe); classifying
  113. // notice, info, and debug as "normal", and all others as
  114. // "severe"
  115. monitor_custom_event($priority, $message, ($priority > 4) ? 0 : 1, $event);
  116. }
  117. } else {
  118. monitor_custom_event($priority, $message);
  119. }
  120. }
  121. }