MongoLog.php 5.5 KB

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