|
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: ZendMonitor.php 23351 2010-11-16 18:09:45Z matthew $ |
|
21 */ |
|
22 |
|
23 /** Zend_Log_Writer_Abstract */ |
|
24 require_once 'Zend/Log/Writer/Abstract.php'; |
|
25 |
|
26 /** |
|
27 * @category Zend |
|
28 * @package Zend_Log |
|
29 * @subpackage Writer |
|
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
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 $ |
|
33 */ |
|
34 class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract |
|
35 { |
|
36 /** |
|
37 * Is Zend Monitor enabled? |
|
38 * @var bool |
|
39 */ |
|
40 protected $_isEnabled = true; |
|
41 |
|
42 /** |
|
43 * Is this for a Zend Server intance? |
|
44 * @var bool |
|
45 */ |
|
46 protected $_isZendServer = false; |
|
47 |
|
48 /** |
|
49 * @throws Zend_Log_Exception if Zend Monitor extension not present |
|
50 */ |
|
51 public function __construct() |
|
52 { |
|
53 if (!function_exists('monitor_custom_event')) { |
|
54 $this->_isEnabled = false; |
|
55 } |
|
56 if (function_exists('zend_monitor_custom_event')) { |
|
57 $this->_isZendServer = true; |
|
58 } |
|
59 } |
|
60 |
|
61 /** |
|
62 * Create a new instance of Zend_Log_Writer_ZendMonitor |
|
63 * |
|
64 * @param array|Zend_Config $config |
|
65 * @return Zend_Log_Writer_Syslog |
|
66 * @throws Zend_Log_Exception |
|
67 */ |
|
68 static public function factory($config) |
|
69 { |
|
70 return new self(); |
|
71 } |
|
72 |
|
73 /** |
|
74 * Is logging to this writer enabled? |
|
75 * |
|
76 * 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 * writer is enabled. |
|
79 * |
|
80 * @return bool |
|
81 */ |
|
82 public function isEnabled() |
|
83 { |
|
84 return $this->_isEnabled; |
|
85 } |
|
86 |
|
87 /** |
|
88 * Log a message to this writer. |
|
89 * |
|
90 * @param array $event log data event |
|
91 * @return void |
|
92 */ |
|
93 public function write($event) |
|
94 { |
|
95 if (!$this->isEnabled()) { |
|
96 return; |
|
97 } |
|
98 |
|
99 parent::write($event); |
|
100 } |
|
101 |
|
102 /** |
|
103 * Write a message to the log. |
|
104 * |
|
105 * @param array $event log data event |
|
106 * @return void |
|
107 */ |
|
108 protected function _write($event) |
|
109 { |
|
110 $priority = $event['priority']; |
|
111 $message = $event['message']; |
|
112 unset($event['priority'], $event['message']); |
|
113 |
|
114 if (!empty($event)) { |
|
115 if ($this->_isZendServer) { |
|
116 // On Zend Server; third argument should be the event |
|
117 zend_monitor_custom_event($priority, $message, $event); |
|
118 } else { |
|
119 // On Zend Platform; third argument is severity -- either |
|
120 // 0 or 1 -- and fourth is optional (event) |
|
121 // Severity is either 0 (normal) or 1 (severe); classifying |
|
122 // notice, info, and debug as "normal", and all others as |
|
123 // "severe" |
|
124 monitor_custom_event($priority, $message, ($priority > 4) ? 0 : 1, $event); |
|
125 } |
|
126 } else { |
|
127 monitor_custom_event($priority, $message); |
|
128 } |
|
129 } |
|
130 } |