AbstractLogger.php 3.0 KB

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