You are here

class WatchdogLogger in Service Container 7

Same name and namespace in other branches
  1. 7.2 src/Logger/WatchdogLogger.php \Drupal\service_container\Logger\WatchdogLogger

Implements the PSR-3 logger with watchdog.

@codeCoverageIgnore

Hierarchy

Expanded class hierarchy of WatchdogLogger

1 file declares its use of WatchdogLogger
WatchdogLoggerTest.php in tests/src/Logger/WatchdogLoggerTest.php
Contains \Drupal\Tests\service_container\Logger\WatchdogLoggerTest.

File

src/Logger/WatchdogLogger.php, line 19
Contains \Drupal\service_container\Logger\WatchdogLogger.

Namespace

Drupal\service_container\Logger
View source
class WatchdogLogger extends LoggerBase implements LoggerInterface {

  /**
   * The Drupal7 service.
   *
   * @var \Drupal\service_container\Legacy\Drupal7
   */
  protected $drupal7;

  /**
   * Constructs a WatchdogLogger object.
   *
   * @param \Drupal\service_container\Legacy\Drupal7 $drupal7
   *   The Drupal7 service.
   */
  public function __construct(Drupal7 $drupal7) {
    $this->drupal7 = $drupal7;
  }

  /**
   * {@inheritdoc}
   */
  public function log($level, $message, array $context = array()) {
    $map = array(
      LogLevel::EMERGENCY => WATCHDOG_EMERGENCY,
      LogLevel::DEBUG => WATCHDOG_DEBUG,
      LogLevel::INFO => WATCHDOG_INFO,
      LogLevel::ALERT => WATCHDOG_ALERT,
      LogLevel::CRITICAL => WATCHDOG_CRITICAL,
      LogLevel::ERROR => WATCHDOG_ERROR,
      LogLevel::NOTICE => WATCHDOG_NOTICE,
    );
    $watchdog_level = $map[$level];

    // Map the logger channel to the watchdog type.
    $type = isset($context['channel']) ? $context['channel'] : 'default';
    unset($context['channel']);
    $this->drupal7
      ->watchdog($type, $message, $context, $watchdog_level);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LoggerBase::alert public function Action must be taken immediately. Overrides LoggerInterface::alert
LoggerBase::critical public function Critical conditions. Overrides LoggerInterface::critical
LoggerBase::debug public function Detailed debug information. Overrides LoggerInterface::debug
LoggerBase::emergency public function System is unusable. Overrides LoggerInterface::emergency
LoggerBase::error public function Runtime errors that do not require immediate action but should typically be logged and monitored. Overrides LoggerInterface::error
LoggerBase::info public function Interesting events. Overrides LoggerInterface::info
LoggerBase::notice public function Normal but significant events. Overrides LoggerInterface::notice
LoggerBase::warning public function Exceptional occurrences that are not errors. Overrides LoggerInterface::warning
WatchdogLogger::$drupal7 protected property The Drupal7 service.
WatchdogLogger::log public function Logs with an arbitrary level. Overrides LoggerInterface::log
WatchdogLogger::__construct public function Constructs a WatchdogLogger object.