Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   1  <?php
   2  
   3  namespace Psr\Log;
   4  
   5  /**
   6   * This is a simple Logger trait that classes unable to extend AbstractLogger
   7   * (because they extend another class, etc) can include.
   8   *
   9   * It simply delegates all log-level-specific methods to the `log` method to
  10   * reduce boilerplate code that a simple Logger that does the same thing with
  11   * messages regardless of the error level has to implement.
  12   */
  13  trait LoggerTrait
  14  {
  15      /**
  16       * System is unusable.
  17       *
  18       * @param string $message
  19       * @param array  $context
  20       *
  21       * @return void
  22       */
  23      public function emergency($message, array $context = array())
  24      {
  25          $this->log(LogLevel::EMERGENCY, $message, $context);
  26      }
  27  
  28      /**
  29       * Action must be taken immediately.
  30       *
  31       * Example: Entire website down, database unavailable, etc. This should
  32       * trigger the SMS alerts and wake you up.
  33       *
  34       * @param string $message
  35       * @param array  $context
  36       *
  37       * @return void
  38       */
  39      public function alert($message, array $context = array())
  40      {
  41          $this->log(LogLevel::ALERT, $message, $context);
  42      }
  43  
  44      /**
  45       * Critical conditions.
  46       *
  47       * Example: Application component unavailable, unexpected exception.
  48       *
  49       * @param string $message
  50       * @param array  $context
  51       *
  52       * @return void
  53       */
  54      public function critical($message, array $context = array())
  55      {
  56          $this->log(LogLevel::CRITICAL, $message, $context);
  57      }
  58  
  59      /**
  60       * Runtime errors that do not require immediate action but should typically
  61       * be logged and monitored.
  62       *
  63       * @param string $message
  64       * @param array  $context
  65       *
  66       * @return void
  67       */
  68      public function error($message, array $context = array())
  69      {
  70          $this->log(LogLevel::ERROR, $message, $context);
  71      }
  72  
  73      /**
  74       * Exceptional occurrences that are not errors.
  75       *
  76       * Example: Use of deprecated APIs, poor use of an API, undesirable things
  77       * that are not necessarily wrong.
  78       *
  79       * @param string $message
  80       * @param array  $context
  81       *
  82       * @return void
  83       */
  84      public function warning($message, array $context = array())
  85      {
  86          $this->log(LogLevel::WARNING, $message, $context);
  87      }
  88  
  89      /**
  90       * Normal but significant events.
  91       *
  92       * @param string $message
  93       * @param array  $context
  94       *
  95       * @return void
  96       */
  97      public function notice($message, array $context = array())
  98      {
  99          $this->log(LogLevel::NOTICE, $message, $context);
 100      }
 101  
 102      /**
 103       * Interesting events.
 104       *
 105       * Example: User logs in, SQL logs.
 106       *
 107       * @param string $message
 108       * @param array  $context
 109       *
 110       * @return void
 111       */
 112      public function info($message, array $context = array())
 113      {
 114          $this->log(LogLevel::INFO, $message, $context);
 115      }
 116  
 117      /**
 118       * Detailed debug information.
 119       *
 120       * @param string $message
 121       * @param array  $context
 122       *
 123       * @return void
 124       */
 125      public function debug($message, array $context = array())
 126      {
 127          $this->log(LogLevel::DEBUG, $message, $context);
 128      }
 129  
 130      /**
 131       * Logs with an arbitrary level.
 132       *
 133       * @param mixed  $level
 134       * @param string $message
 135       * @param array  $context
 136       *
 137       * @return void
 138       *
 139       * @throws \Psr\Log\InvalidArgumentException
 140       */
 141      abstract public function log($level, $message, array $context = array());
 142  }