RfcLoggerTrait.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Drupal\Core\Logger;
  3. /**
  4. * A copy of \Psr\Log\LoggerTrait that uses RFC 5424 compliant log levels.
  5. *
  6. * Internal Drupal logger implementations should use this trait instead of
  7. * \Psr\Log\LoggerTrait. Callers of those implementations are responsible for
  8. * translating any other log level format to RFC 5424 compliant integers.
  9. *
  10. * @see https://groups.google.com/forum/#!topic/php-fig/Rc5YDhNdGz4
  11. * @see https://www.drupal.org/node/2267545
  12. */
  13. trait RfcLoggerTrait {
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public function emergency($message, array $context = []) {
  18. $this->log(RfcLogLevel::EMERGENCY, $message, $context);
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function alert($message, array $context = []) {
  24. $this->log(RfcLogLevel::ALERT, $message, $context);
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function critical($message, array $context = []) {
  30. $this->log(RfcLogLevel::CRITICAL, $message, $context);
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function error($message, array $context = []) {
  36. $this->log(RfcLogLevel::ERROR, $message, $context);
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function warning($message, array $context = []) {
  42. $this->log(RfcLogLevel::WARNING, $message, $context);
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function notice($message, array $context = []) {
  48. $this->log(RfcLogLevel::NOTICE, $message, $context);
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function info($message, array $context = []) {
  54. $this->log(RfcLogLevel::INFO, $message, $context);
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function debug($message, array $context = []) {
  60. $this->log(RfcLogLevel::DEBUG, $message, $context);
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. abstract public function log($level, $message, array $context = []);
  66. }