|
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
|
|
|
class MongoLog |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.none |
|
20
|
|
|
*/ |
|
21
|
|
|
const NONE = 0; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.all |
|
25
|
|
|
*/ |
|
26
|
|
|
const ALL = 31; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.warning |
|
30
|
|
|
*/ |
|
31
|
|
|
const WARNING = 1; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.info |
|
35
|
|
|
*/ |
|
36
|
|
|
const INFO = 2; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.fine |
|
40
|
|
|
*/ |
|
41
|
|
|
const FINE = 4; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.rs |
|
45
|
|
|
*/ |
|
46
|
|
|
const RS = 1; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.pool |
|
50
|
|
|
*/ |
|
51
|
|
|
const POOL = 1; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.con |
|
55
|
|
|
*/ |
|
56
|
|
|
const CON = 2; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.io |
|
60
|
|
|
*/ |
|
61
|
|
|
const IO = 4; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.server |
|
65
|
|
|
*/ |
|
66
|
|
|
const SERVER = 8; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.parse |
|
70
|
|
|
*/ |
|
71
|
|
|
const PARSE = 16; |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
private static $callback; |
|
75
|
|
|
private static $level; |
|
76
|
|
|
private static $module; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* (PECL mongo >= 1.3.0) |
|
80
|
|
|
* Gets the previously set callback function |
|
81
|
|
|
* |
|
82
|
|
|
* @return callable|null |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function getCallback() |
|
85
|
|
|
{ |
|
86
|
|
|
return self::$callback; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* (PECL mongo >= 1.3.0)<br/> |
|
91
|
|
|
* <p> |
|
92
|
|
|
* This function will set a callback function to be called for {@link http://www.php.net/manual/en/class.mongolog.php MongoLog} events |
|
93
|
|
|
* instead of triggering warnings. |
|
94
|
|
|
* </p> |
|
95
|
|
|
* @link http://www.php.net/manual/en/mongolog.setcallback.php |
|
96
|
|
|
* @param callable $log_function <p> |
|
97
|
|
|
* The function to be called on events. |
|
98
|
|
|
* </p> |
|
99
|
|
|
* <p> |
|
100
|
|
|
* The function should have the following prototype |
|
101
|
|
|
* </p> |
|
102
|
|
|
* |
|
103
|
|
|
* <em>log_function</em> ( <em>int</em> <em>$module</em> , <em>int</em> <em>$level</em>, <em>string</em> <em>$message</em>) |
|
104
|
|
|
* <ul> |
|
105
|
|
|
* <li> |
|
106
|
|
|
* <b><i>module</i></b> |
|
107
|
|
|
* |
|
108
|
|
|
* <p>One of the {@link http://www.php.net/manual/en/class.mongolog.php#mongolog.constants.module MongoLog module constants}.</p> |
|
109
|
|
|
* </li> |
|
110
|
|
|
* <li> |
|
111
|
|
|
* <b><i>level</i></b> |
|
112
|
|
|
* |
|
113
|
|
|
* <p>One of the {@link http://www.php.net/manual/en/class.mongolog.php#mongolog.constants.level MongoLog level constants}.</p> |
|
114
|
|
|
* </li |
|
115
|
|
|
* <li> |
|
116
|
|
|
* <b><i>message</i></b> |
|
117
|
|
|
* |
|
118
|
|
|
* <p>The log message itself.</p></li> |
|
119
|
|
|
* <ul> |
|
120
|
|
|
* @return boolean Returns <b>TRUE</b> on success or <b>FALSE</b> on failure. |
|
121
|
|
|
*/ |
|
122
|
|
|
public static function setCallback(callable $log_function ) |
|
123
|
|
|
{ |
|
124
|
|
|
self::$callback = $log_function; |
|
125
|
|
|
return true; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* This function can be used to set how verbose logging should be and the types of |
|
130
|
|
|
* activities that should be logged. Use the constants described in the MongoLog |
|
131
|
|
|
* section with bitwise operators to specify levels. |
|
132
|
|
|
* |
|
133
|
|
|
* @link http://php.net/manual/en/mongolog.setlevel.php |
|
134
|
|
|
* @static |
|
135
|
|
|
* @param int $level The levels you would like to log |
|
136
|
|
|
* @return void |
|
137
|
|
|
*/ |
|
138
|
|
|
public static function setLevel($level) |
|
139
|
|
|
{ |
|
140
|
|
|
self::$level = $level; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* This can be used to see the log level. Use the constants described in the |
|
145
|
|
|
* MongoLog section with bitwise operators to check the level. |
|
146
|
|
|
* |
|
147
|
|
|
* @link http://php.net/manual/en/mongolog.getlevel.php |
|
148
|
|
|
* @static |
|
149
|
|
|
* @return int Returns the current level |
|
150
|
|
|
*/ |
|
151
|
|
|
public static function getLevel() |
|
152
|
|
|
{ |
|
153
|
|
|
return self::$level; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* This function can be used to set which parts of the driver's functionality |
|
158
|
|
|
* should be logged. Use the constants described in the MongoLog section with |
|
159
|
|
|
* bitwise operators to specify modules. |
|
160
|
|
|
* |
|
161
|
|
|
* @link http://php.net/manual/en/mongolog.setmodule.php |
|
162
|
|
|
* @static |
|
163
|
|
|
* @param int $module The module(s) you would like to log |
|
164
|
|
|
* @return void |
|
165
|
|
|
*/ |
|
166
|
|
|
public static function setModule($module) |
|
167
|
|
|
{ |
|
168
|
|
|
self::$module = $module; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* This function can be used to see which parts of the driver's functionality are |
|
173
|
|
|
* being logged. Use the constants described in the MongoLog section with bitwise |
|
174
|
|
|
* operators to check if specific modules are being logged. |
|
175
|
|
|
* |
|
176
|
|
|
* @link http://php.net/manual/en/mongolog.getmodule.php |
|
177
|
|
|
* @static |
|
178
|
|
|
* @return int Returns the modules currently being logged |
|
179
|
|
|
*/ |
|
180
|
|
|
public static function getModule() |
|
181
|
|
|
{ |
|
182
|
|
|
return self::$module; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.