You are here

class TextimageLogger in Textimage 8.4

Same name and namespace in other branches
  1. 8.3 src/TextimageLogger.php \Drupal\textimage\TextimageLogger

Defines a Textimage logger.

Hierarchy

Expanded class hierarchy of TextimageLogger

1 string reference to 'TextimageLogger'
textimage.services.yml in ./textimage.services.yml
textimage.services.yml
1 service uses TextimageLogger
textimage.logger in ./textimage.services.yml
Drupal\textimage\TextimageLogger

File

src/TextimageLogger.php, line 16

Namespace

Drupal\textimage
View source
class TextimageLogger extends LoggerChannel {
  use StringTranslationTrait;
  use MessengerTrait;

  /**
   * The configuration factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The Textimage logger channel.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $loggerChannel;

  /**
   * Constructs a TextimageLogger object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param \Psr\Log\LoggerInterface $logger_channel
   *   The Textimage logger channel.
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   The current user.
   */
  public function __construct(ConfigFactoryInterface $config_factory, LoggerInterface $logger_channel, AccountInterface $current_user) {
    $this->configFactory = $config_factory;
    $this->loggerChannel = $logger_channel;
    $this->currentUser = $current_user;
  }

  /**
   * {@inheritdoc}
   */
  public function log($level, $message, array $context = []) {

    // Convert to integer equivalent for consistency with RFC 5424.
    $level_code = is_string($level) ? $this->levelTranslation[$level] : $level;

    // Process debug entries only if required.
    if ($level_code == RfcLogLevel::DEBUG && !$this->configFactory
      ->get('textimage.settings')
      ->get('debug')) {
      return NULL;
    }

    // Logs through the logger channel.
    $this->loggerChannel
      ->log($level_code, $message, $context);

    // Display the message to qualified users.
    if ($this->currentUser
      ->hasPermission('administer site configuration') || $this->currentUser
      ->hasPermission('administer image styles')) {
      switch ($level_code) {
        case RfcLogLevel::DEBUG:
        case RfcLogLevel::INFO:
        case RfcLogLevel::NOTICE:
          $type = 'status';
          break;
        case RfcLogLevel::WARNING:
          $type = 'warning';
          break;
        default:
          $type = 'error';
      }

      // @todo replace call to $this->t
      // @codingStandardsIgnoreLine
      $this
        ->messenger()
        ->addMessage($this
        ->t($message, $context), $type);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LoggerChannel::$callDepth protected property Number of times LoggerChannel::log() has been called for a single message.
LoggerChannel::$channel protected property The name of the channel of this logger instance.
LoggerChannel::$currentUser protected property The current user object.
LoggerChannel::$levelTranslation protected property Map of PSR3 log constants to RFC 5424 log constants.
LoggerChannel::$loggers protected property An array of arrays of \Psr\Log\LoggerInterface keyed by priority.
LoggerChannel::$requestStack protected property The request stack object.
LoggerChannel::addLogger public function Adds a logger. Overrides LoggerChannelInterface::addLogger
LoggerChannel::MAX_CALL_DEPTH constant Maximum call depth to self::log() for a single log message.
LoggerChannel::setCurrentUser public function Sets the current user. Overrides LoggerChannelInterface::setCurrentUser
LoggerChannel::setLoggers public function Sets the loggers for this channel. Overrides LoggerChannelInterface::setLoggers
LoggerChannel::setRequestStack public function Sets the request stack. Overrides LoggerChannelInterface::setRequestStack
LoggerChannel::sortLoggers protected function Sorts loggers according to priority.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TextimageLogger::$configFactory protected property The configuration factory.
TextimageLogger::$loggerChannel protected property The Textimage logger channel.
TextimageLogger::log public function Logs with an arbitrary level. Overrides LoggerChannel::log
TextimageLogger::__construct public function Constructs a TextimageLogger object. Overrides LoggerChannel::__construct