File indexing completed on 2024-12-22 05:36:50
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Log 0017 * @subpackage Writer 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** Zend_Log_Writer_Abstract */ 0024 // require_once 'Zend/Log/Writer/Abstract.php'; 0025 0026 /** 0027 * @category Zend 0028 * @package Zend_Log 0029 * @subpackage Writer 0030 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0031 * @license http://framework.zend.com/license/new-bsd New BSD License 0032 * @version $Id$ 0033 */ 0034 class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract 0035 { 0036 /** 0037 * Is Zend Monitor enabled? 0038 * 0039 * @var boolean 0040 */ 0041 protected $_isEnabled = true; 0042 0043 /** 0044 * Is this for a Zend Server intance? 0045 * 0046 * @var boolean 0047 */ 0048 protected $_isZendServer = false; 0049 0050 /** 0051 * @return void 0052 */ 0053 public function __construct() 0054 { 0055 if (!function_exists('monitor_custom_event')) { 0056 $this->_isEnabled = false; 0057 } 0058 if (function_exists('zend_monitor_custom_event')) { 0059 $this->_isZendServer = true; 0060 } 0061 } 0062 0063 /** 0064 * Create a new instance of Zend_Log_Writer_ZendMonitor 0065 * 0066 * @param array|Zend_Config $config 0067 * @return Zend_Log_Writer_ZendMonitor 0068 */ 0069 static public function factory($config) 0070 { 0071 return new self(); 0072 } 0073 0074 /** 0075 * Is logging to this writer enabled? 0076 * 0077 * If the Zend Monitor extension is not enabled, this log writer will 0078 * fail silently. You can query this method to determine if the log 0079 * writer is enabled. 0080 * 0081 * @return boolean 0082 */ 0083 public function isEnabled() 0084 { 0085 return $this->_isEnabled; 0086 } 0087 0088 /** 0089 * Log a message to this writer. 0090 * 0091 * @param array $event log data event 0092 * @return void 0093 */ 0094 public function write($event) 0095 { 0096 if (!$this->isEnabled()) { 0097 return; 0098 } 0099 0100 parent::write($event); 0101 } 0102 0103 /** 0104 * Write a message to the log. 0105 * 0106 * @param array $event log data event 0107 * @return void 0108 */ 0109 protected function _write($event) 0110 { 0111 $priority = $event['priority']; 0112 $message = $event['message']; 0113 unset($event['priority'], $event['message']); 0114 0115 if (!empty($event)) { 0116 if ($this->_isZendServer) { 0117 // On Zend Server; third argument should be the event 0118 zend_monitor_custom_event($priority, $message, $event); 0119 } else { 0120 // On Zend Platform; third argument is severity -- either 0121 // 0 or 1 -- and fourth is optional (event) 0122 // Severity is either 0 (normal) or 1 (severe); classifying 0123 // notice, info, and debug as "normal", and all others as 0124 // "severe" 0125 monitor_custom_event($priority, $message, ($priority > 4) ? 0 : 1, $event); 0126 } 0127 } else { 0128 monitor_custom_event($priority, $message); 0129 } 0130 } 0131 }