Logger.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * This is a simple Logger implementation that other Loggers can inherit from.
  4. *
  5. * It simply delegates all log-level-specific methods to the `log` method to
  6. * reduce boilerplate code that a simple Logger that does the same thing with
  7. * messages regardless of the error level has to implement.
  8. */
  9. abstract class NF_Abstracts_Logger implements NF_Abstracts_LoggerInterface
  10. {
  11. /**
  12. * System is unusable.
  13. *
  14. * @param string $message
  15. * @param array $context
  16. *
  17. * @return null
  18. */
  19. public function emergency($message, array $context = array())
  20. {
  21. $this->log(NF_Abstracts_LogLevel::EMERGENCY, $message, $context);
  22. }
  23. /**
  24. * Action must be taken immediately.
  25. *
  26. * Example: Entire website down, database unavailable, etc. This should
  27. * trigger the SMS alerts and wake you up.
  28. *
  29. * @param string $message
  30. * @param array $context
  31. *
  32. * @return null
  33. */
  34. public function alert($message, array $context = array())
  35. {
  36. $this->log(NF_Abstracts_LogLevel::ALERT, $message, $context);
  37. }
  38. /**
  39. * Critical conditions.
  40. *
  41. * Example: Application component unavailable, unexpected exception.
  42. *
  43. * @param string $message
  44. * @param array $context
  45. *
  46. * @return null
  47. */
  48. public function critical($message, array $context = array())
  49. {
  50. $this->log(NF_Abstracts_LogLevel::CRITICAL, $message, $context);
  51. }
  52. /**
  53. * Runtime errors that do not require immediate action but should typically
  54. * be logged and monitored.
  55. *
  56. * @param string $message
  57. * @param array $context
  58. *
  59. * @return null
  60. */
  61. public function error($message, array $context = array())
  62. {
  63. $this->log(NF_Abstracts_LogLevel::ERROR, $message, $context);
  64. }
  65. /**
  66. * Exceptional occurrences that are not errors.
  67. *
  68. * Example: Use of deprecated APIs, poor use of an API, undesirable things
  69. * that are not necessarily wrong.
  70. *
  71. * @param string $message
  72. * @param array $context
  73. *
  74. * @return null
  75. */
  76. public function warning($message, array $context = array())
  77. {
  78. $this->log(NF_Abstracts_LogLevel::WARNING, $message, $context);
  79. }
  80. /**
  81. * Normal but significant events.
  82. *
  83. * @param string $message
  84. * @param array $context
  85. *
  86. * @return null
  87. */
  88. public function notice($message, array $context = array())
  89. {
  90. $this->log(NF_Abstracts_LogLevel::NOTICE, $message, $context);
  91. }
  92. /**
  93. * Interesting events.
  94. *
  95. * Example: User logs in, SQL logs.
  96. *
  97. * @param string $message
  98. * @param array $context
  99. *
  100. * @return null
  101. */
  102. public function info($message, array $context = array())
  103. {
  104. $this->log(NF_Abstracts_LogLevel::INFO, $message, $context);
  105. }
  106. /**
  107. * Detailed debug information.
  108. *
  109. * @param string $message
  110. * @param array $context
  111. *
  112. * @return null
  113. */
  114. public function debug($message, array $context = array())
  115. {
  116. $this->log(NF_Abstracts_LogLevel::DEBUG, $message, $context);
  117. }
  118. }