web/lib/Zend/Log/Writer/ZendMonitor.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Log
    16  * @package    Zend_Log
    17  * @subpackage Writer
    17  * @subpackage Writer
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: ZendMonitor.php 23351 2010-11-16 18:09:45Z matthew $
    20  * @version    $Id: ZendMonitor.php 24593 2012-01-05 20:35:02Z matthew $
    21  */
    21  */
    22 
    22 
    23 /** Zend_Log_Writer_Abstract */
    23 /** Zend_Log_Writer_Abstract */
    24 require_once 'Zend/Log/Writer/Abstract.php';
    24 require_once 'Zend/Log/Writer/Abstract.php';
    25 
    25 
    26 /**
    26 /**
    27  * @category   Zend
    27  * @category   Zend
    28  * @package    Zend_Log
    28  * @package    Zend_Log
    29  * @subpackage Writer
    29  * @subpackage Writer
    30  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    30  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    32  * @version    $Id: ZendMonitor.php 23351 2010-11-16 18:09:45Z matthew $
    32  * @version    $Id: ZendMonitor.php 24593 2012-01-05 20:35:02Z matthew $
    33  */
    33  */
    34 class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract
    34 class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract
    35 {
    35 {
    36     /**
    36     /**
    37      * Is Zend Monitor enabled?
    37      * Is Zend Monitor enabled?
    38      * @var bool
    38      *
       
    39      * @var boolean
    39      */
    40      */
    40     protected $_isEnabled = true;
    41     protected $_isEnabled = true;
    41 
    42 
    42     /**
    43     /**
    43      * Is this for a Zend Server intance?
    44      * Is this for a Zend Server intance?
    44      * @var bool
    45      *
       
    46      * @var boolean
    45      */
    47      */
    46     protected $_isZendServer = false;
    48     protected $_isZendServer = false;
    47 
    49 
    48     /**
    50     /**
    49      * @throws Zend_Log_Exception if Zend Monitor extension not present
    51      * @return void
    50      */
    52      */
    51     public function __construct()
    53     public function __construct()
    52     {
    54     {
    53         if (!function_exists('monitor_custom_event')) {
    55         if (!function_exists('monitor_custom_event')) {
    54             $this->_isEnabled = false;
    56             $this->_isEnabled = false;
    60 
    62 
    61     /**
    63     /**
    62      * Create a new instance of Zend_Log_Writer_ZendMonitor
    64      * Create a new instance of Zend_Log_Writer_ZendMonitor
    63      *
    65      *
    64      * @param  array|Zend_Config $config
    66      * @param  array|Zend_Config $config
    65      * @return Zend_Log_Writer_Syslog
    67      * @return Zend_Log_Writer_ZendMonitor
    66      * @throws Zend_Log_Exception
       
    67      */
    68      */
    68     static public function factory($config)
    69     static public function factory($config)
    69     {
    70     {
    70         return new self();
    71         return new self();
    71     }
    72     }
    75      *
    76      *
    76      * If the Zend Monitor extension is not enabled, this log writer will
    77      * If the Zend Monitor extension is not enabled, this log writer will
    77      * fail silently. You can query this method to determine if the log
    78      * fail silently. You can query this method to determine if the log
    78      * writer is enabled.
    79      * writer is enabled.
    79      *
    80      *
    80      * @return bool
    81      * @return boolean
    81      */
    82      */
    82     public function isEnabled()
    83     public function isEnabled()
    83     {
    84     {
    84         return $this->_isEnabled;
    85         return $this->_isEnabled;
    85     }
    86     }
    86 
    87 
    87     /**
    88     /**
    88      * Log a message to this writer.
    89      * Log a message to this writer.
    89      *
    90      *
    90      * @param  array $event  log data event
    91      * @param  array $event log data event
    91      * @return void
    92      * @return void
    92      */
    93      */
    93     public function write($event)
    94     public function write($event)
    94     {
    95     {
    95         if (!$this->isEnabled()) {
    96         if (!$this->isEnabled()) {
   100     }
   101     }
   101 
   102 
   102     /**
   103     /**
   103      * Write a message to the log.
   104      * Write a message to the log.
   104      *
   105      *
   105      * @param  array  $event  log data event
   106      * @param  array  $event log data event
   106      * @return void
   107      * @return void
   107      */
   108      */
   108     protected function _write($event)
   109     protected function _write($event)
   109     {
   110     {
   110         $priority = $event['priority'];
   111         $priority = $event['priority'];
   114         if (!empty($event)) {
   115         if (!empty($event)) {
   115             if ($this->_isZendServer) {
   116             if ($this->_isZendServer) {
   116                 // On Zend Server; third argument should be the event
   117                 // On Zend Server; third argument should be the event
   117                 zend_monitor_custom_event($priority, $message, $event);
   118                 zend_monitor_custom_event($priority, $message, $event);
   118             } else {
   119             } else {
   119                 // On Zend Platform; third argument is severity -- either 
   120                 // On Zend Platform; third argument is severity -- either
   120                 // 0 or 1 -- and fourth is optional (event)
   121                 // 0 or 1 -- and fourth is optional (event)
   121                 // Severity is either 0 (normal) or 1 (severe); classifying
   122                 // Severity is either 0 (normal) or 1 (severe); classifying
   122                 // notice, info, and debug as "normal", and all others as 
   123                 // notice, info, and debug as "normal", and all others as
   123                 // "severe"
   124                 // "severe"
   124                 monitor_custom_event($priority, $message, ($priority > 4) ? 0 : 1, $event);
   125                 monitor_custom_event($priority, $message, ($priority > 4) ? 0 : 1, $event);
   125             }
   126             }
   126         } else {
   127         } else {
   127             monitor_custom_event($priority, $message);
   128             monitor_custom_event($priority, $message);