1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
if (class_exists('MongoLog', false)) { |
17
|
|
|
return; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
class MongoLog |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.none |
24
|
|
|
*/ |
25
|
|
|
const NONE = 0; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.all |
29
|
|
|
*/ |
30
|
|
|
const ALL = 31; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.warning |
34
|
|
|
*/ |
35
|
|
|
const WARNING = 1; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.info |
39
|
|
|
*/ |
40
|
|
|
const INFO = 2; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.fine |
44
|
|
|
*/ |
45
|
|
|
const FINE = 4; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.rs |
49
|
|
|
*/ |
50
|
|
|
const RS = 1; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.pool |
54
|
|
|
*/ |
55
|
|
|
const POOL = 1; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.con |
59
|
|
|
*/ |
60
|
|
|
const CON = 2; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.io |
64
|
|
|
*/ |
65
|
|
|
const IO = 4; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.server |
69
|
|
|
*/ |
70
|
|
|
const SERVER = 8; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.parse |
74
|
|
|
*/ |
75
|
|
|
const PARSE = 16; |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
private static $callback; |
79
|
|
|
private static $level; |
80
|
|
|
private static $module; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* (PECL mongo >= 1.3.0) |
84
|
|
|
* Gets the previously set callback function |
85
|
|
|
* |
86
|
|
|
* @return callable|null |
87
|
|
|
*/ |
88
|
|
|
public static function getCallback() |
89
|
|
|
{ |
90
|
|
|
return self::$callback; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* (PECL mongo >= 1.3.0)<br/> |
95
|
|
|
* <p> |
96
|
|
|
* This function will set a callback function to be called for {@link http://www.php.net/manual/en/class.mongolog.php MongoLog} events |
97
|
|
|
* instead of triggering warnings. |
98
|
|
|
* </p> |
99
|
|
|
* @link http://www.php.net/manual/en/mongolog.setcallback.php |
100
|
|
|
* @param callable $log_function <p> |
101
|
|
|
* The function to be called on events. |
102
|
|
|
* </p> |
103
|
|
|
* <p> |
104
|
|
|
* The function should have the following prototype |
105
|
|
|
* </p> |
106
|
|
|
* |
107
|
|
|
* <em>log_function</em> ( <em>int</em> <em>$module</em> , <em>int</em> <em>$level</em>, <em>string</em> <em>$message</em>) |
108
|
|
|
* <ul> |
109
|
|
|
* <li> |
110
|
|
|
* <b><i>module</i></b> |
111
|
|
|
* |
112
|
|
|
* <p>One of the {@link http://www.php.net/manual/en/class.mongolog.php#mongolog.constants.module MongoLog module constants}.</p> |
113
|
|
|
* </li> |
114
|
|
|
* <li> |
115
|
|
|
* <b><i>level</i></b> |
116
|
|
|
* |
117
|
|
|
* <p>One of the {@link http://www.php.net/manual/en/class.mongolog.php#mongolog.constants.level MongoLog level constants}.</p> |
118
|
|
|
* </li |
119
|
|
|
* <li> |
120
|
|
|
* <b><i>message</i></b> |
121
|
|
|
* |
122
|
|
|
* <p>The log message itself.</p></li> |
123
|
|
|
* <ul> |
124
|
|
|
* @return boolean Returns <b>TRUE</b> on success or <b>FALSE</b> on failure. |
125
|
|
|
*/ |
126
|
|
|
public static function setCallback(callable $log_function) |
127
|
|
|
{ |
128
|
|
|
self::$callback = $log_function; |
129
|
|
|
return true; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* This function can be used to set how verbose logging should be and the types of |
134
|
|
|
* activities that should be logged. Use the constants described in the MongoLog |
135
|
|
|
* section with bitwise operators to specify levels. |
136
|
|
|
* |
137
|
|
|
* @link http://php.net/manual/en/mongolog.setlevel.php |
138
|
|
|
* @static |
139
|
|
|
* @param int $level The levels you would like to log |
140
|
|
|
* @return void |
141
|
|
|
*/ |
142
|
|
|
public static function setLevel($level) |
143
|
|
|
{ |
144
|
|
|
self::$level = $level; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* This can be used to see the log level. Use the constants described in the |
149
|
|
|
* MongoLog section with bitwise operators to check the level. |
150
|
|
|
* |
151
|
|
|
* @link http://php.net/manual/en/mongolog.getlevel.php |
152
|
|
|
* @static |
153
|
|
|
* @return int Returns the current level |
154
|
|
|
*/ |
155
|
|
|
public static function getLevel() |
156
|
|
|
{ |
157
|
|
|
return self::$level; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* This function can be used to set which parts of the driver's functionality |
162
|
|
|
* should be logged. Use the constants described in the MongoLog section with |
163
|
|
|
* bitwise operators to specify modules. |
164
|
|
|
* |
165
|
|
|
* @link http://php.net/manual/en/mongolog.setmodule.php |
166
|
|
|
* @static |
167
|
|
|
* @param int $module The module(s) you would like to log |
168
|
|
|
* @return void |
169
|
|
|
*/ |
170
|
|
|
public static function setModule($module) |
171
|
|
|
{ |
172
|
|
|
self::$module = $module; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* This function can be used to see which parts of the driver's functionality are |
177
|
|
|
* being logged. Use the constants described in the MongoLog section with bitwise |
178
|
|
|
* operators to check if specific modules are being logged. |
179
|
|
|
* |
180
|
|
|
* @link http://php.net/manual/en/mongolog.getmodule.php |
181
|
|
|
* @static |
182
|
|
|
* @return int Returns the modules currently being logged |
183
|
|
|
*/ |
184
|
|
|
public static function getModule() |
185
|
|
|
{ |
186
|
|
|
return self::$module; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|