2
0

ZendMonitor.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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$
  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-2010 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. * Create a new instance of Zend_Log_Writer_ZendMonitor
  50. *
  51. * @param array|Zend_Config $config
  52. * @return Zend_Log_Writer_Syslog
  53. * @throws Zend_Log_Exception
  54. */
  55. static public function factory($config)
  56. {
  57. return new self();
  58. }
  59. /**
  60. * Is logging to this writer enabled?
  61. *
  62. * If the Zend Monitor extension is not enabled, this log writer will
  63. * fail silently. You can query this method to determine if the log
  64. * writer is enabled.
  65. *
  66. * @return bool
  67. */
  68. public function isEnabled()
  69. {
  70. return $this->_isEnabled;
  71. }
  72. /**
  73. * Log a message to this writer.
  74. *
  75. * @param array $event log data event
  76. * @return void
  77. */
  78. public function write($event)
  79. {
  80. if (!$this->isEnabled()) {
  81. return;
  82. }
  83. parent::write($event);
  84. }
  85. /**
  86. * Write a message to the log.
  87. *
  88. * @param array $event log data event
  89. * @return void
  90. */
  91. protected function _write($event)
  92. {
  93. $priority = $event['priority'];
  94. $message = $event['message'];
  95. unset($event['priority'], $event['message']);
  96. if (!empty($event)) {
  97. monitor_custom_event($priority, $message, $event);
  98. } else {
  99. monitor_custom_event($priority, $message);
  100. }
  101. }
  102. }