You are here

class Logger in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 src/Logger.php \Drupal\simple_sitemap\Logger
  2. 8.2 src/Logger.php \Drupal\simple_sitemap\Logger

Class Logger

Hierarchy

Expanded class hierarchy of Logger

10 files declare their use of Logger
CustomUrlGenerator.php in src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php
EntityManager.php in src/Manager/EntityManager.php
EntityMenuLinkContentUrlGenerator.php in src/Plugin/simple_sitemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php
EntityUrlGenerator.php in src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php
EntityUrlGeneratorBase.php in src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGeneratorBase.php

... See full list

1 string reference to 'Logger'
simple_sitemap.services.yml in ./simple_sitemap.services.yml
simple_sitemap.services.yml
1 service uses Logger
simple_sitemap.logger in ./simple_sitemap.services.yml
Drupal\simple_sitemap\Logger

File

src/Logger.php, line 13

Namespace

Drupal\simple_sitemap
View source
class Logger {
  use StringTranslationTrait;

  /*
   * Can be debug/info/notice/warning/error.
   */
  protected const LOG_SEVERITY_LEVEL_DEFAULT = 'notice';

  /*
   * Can be status/warning/error.
   */
  protected const DISPLAY_MESSAGE_TYPE_DEFAULT = 'status';

  /**
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  protected $messenger;

  /**
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $currentUser;

  /**
   * @var string
   */
  protected $message = '';

  /**
   * @var array
   */
  protected $substitutions = [];

  /**
   * Logger constructor.
   * @param \Psr\Log\LoggerInterface $logger
   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
   * @param \Drupal\Core\Session\AccountProxyInterface $current_user
   */
  public function __construct(LoggerInterface $logger, MessengerInterface $messenger, AccountProxyInterface $current_user) {
    $this->logger = $logger;
    $this->messenger = $messenger;
    $this->currentUser = $current_user;
  }

  /**
   * @param $message
   * @param array $substitutions
   *
   * @return $this
   */
  public function m($message, array $substitutions = []) : Logger {
    $this->message = $message;
    $this->substitutions = $substitutions;
    return $this;
  }

  /**
   * @param string $logSeverityLevel
   *
   * @return $this
   */
  public function log(string $logSeverityLevel = self::LOG_SEVERITY_LEVEL_DEFAULT) : Logger {
    $this->logger
      ->{$logSeverityLevel}(strtr($this->message, $this->substitutions));
    return $this;
  }

  /**
   * @param string $displayMessageType
   * @param string $permission
   *
   * @return $this
   */
  public function display(string $displayMessageType = self::DISPLAY_MESSAGE_TYPE_DEFAULT, string $permission = '') : Logger {
    if (empty($permission) || $this->currentUser
      ->hasPermission($permission)) {
      $this->messenger
        ->addMessage($this
        ->t($this->message, $this->substitutions), $displayMessageType);
    }
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Logger::$currentUser protected property
Logger::$logger protected property
Logger::$message protected property
Logger::$messenger protected property
Logger::$substitutions protected property
Logger::display public function
Logger::DISPLAY_MESSAGE_TYPE_DEFAULT protected constant
Logger::log public function
Logger::LOG_SEVERITY_LEVEL_DEFAULT protected constant
Logger::m public function
Logger::__construct public function Logger constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
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.