You are here

class Logger in Monolog 8

Same name and namespace in other branches
  1. 2.x src/Logger/Logger.php \Drupal\monolog\Logger\Logger

Logger class for the Drupal Monolog module.

Allows the channel to be modified after the class is instantiated. This is normally not a good idea, but it is necessary to reconcile the differences in the Monolog library and how the watchdog type relates to the logging facility.

Hierarchy

Expanded class hierarchy of Logger

1 file declares its use of Logger
LoggerTest.php in tests/src/Unit/Logger/LoggerTest.php

File

src/Logger/Logger.php, line 20

Namespace

Drupal\monolog\Logger
View source
class Logger extends BaseLogger implements LoggerChannelInterface {

  /**
   * Map of RFC 5424 log constants to Monolog log constants.
   *
   * @var array
   */
  protected $levelTranslation = array(
    RfcLogLevel::EMERGENCY => MonologLogLevel::EMERGENCY,
    RfcLogLevel::ALERT => MonologLogLevel::ALERT,
    RfcLogLevel::CRITICAL => MonologLogLevel::CRITICAL,
    RfcLogLevel::ERROR => MonologLogLevel::ERROR,
    RfcLogLevel::WARNING => MonologLogLevel::WARNING,
    RfcLogLevel::NOTICE => MonologLogLevel::NOTICE,
    RfcLogLevel::INFO => MonologLogLevel::INFO,
    RfcLogLevel::DEBUG => MonologLogLevel::DEBUG,
  );

  /**
   * {@inheritdoc}
   */
  public function addRecord($level, $message, array $context = array()) {
    if (array_key_exists($level, $this->levelTranslation)) {
      $level = $this->levelTranslation[$level];
    }
    parent::addRecord($level, $message, $context);
  }

  /**
   * {@inheritdoc}
   */
  public function setRequestStack(RequestStack $requestStack = NULL) {

    // Do nothing, use a handler for this.
  }

  /**
   * {@inheritdoc}
   */
  public function setCurrentUser(AccountInterface $current_user = NULL) {

    // Do nothing, use a handler for this.
  }

  /**
   * {@inheritdoc}
   */
  public function setLoggers(array $loggers) {

    // Do nothing.
  }

  /**
   * {@inheritdoc}
   */
  public function addLogger(LoggerInterface $logger, $priority = 0) {

    // Do nothing.
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Logger::$levelTranslation protected property Map of RFC 5424 log constants to Monolog log constants.
Logger::addLogger public function Adds a logger. Overrides LoggerChannelInterface::addLogger
Logger::addRecord public function
Logger::setCurrentUser public function Sets the current user. Overrides LoggerChannelInterface::setCurrentUser
Logger::setLoggers public function Sets the loggers for this channel. Overrides LoggerChannelInterface::setLoggers
Logger::setRequestStack public function Sets the request stack. Overrides LoggerChannelInterface::setRequestStack