MongoLog.php 5.5 KB

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