ZendMonitor.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @version $Id$
  31. */
  32. class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract
  33. {
  34. /**
  35. * Is Zend Monitor enabled?
  36. * @var bool
  37. */
  38. protected $_isEnabled = true;
  39. /**
  40. * @throws Zend_Log_Exception if Zend Monitor extension not present
  41. */
  42. public function __construct()
  43. {
  44. if (!function_exists('monitor_custom_event')) {
  45. $this->_isEnabled = false;
  46. }
  47. }
  48. /**
  49. * Is logging to this writer enabled?
  50. *
  51. * If the Zend Monitor extension is not enabled, this log writer will
  52. * fail silently. You can query this method to determine if the log
  53. * writer is enabled.
  54. *
  55. * @return bool
  56. */
  57. public function isEnabled()
  58. {
  59. return $this->_isEnabled;
  60. }
  61. /**
  62. * Log a message to this writer.
  63. *
  64. * @param array $event log data event
  65. * @return void
  66. */
  67. public function write($event)
  68. {
  69. if (!$this->isEnabled()) {
  70. return;
  71. }
  72. parent::write($event);
  73. }
  74. /**
  75. * Write a message to the log.
  76. *
  77. * @param array $event log data event
  78. * @return void
  79. */
  80. protected function _write($event)
  81. {
  82. $priority = $event['priority'];
  83. $message = $event['message'];
  84. unset($event['priority'], $event['message']);
  85. if (!empty($event)) {
  86. monitor_custom_event($priority, $message, $event);
  87. } else {
  88. monitor_custom_event($priority, $message);
  89. }
  90. }
  91. }