View source
<?php
namespace Drupal\simple_sitemap;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Session\AccountProxyInterface;
use Psr\Log\LoggerInterface;
class Logger {
use StringTranslationTrait;
const LOG_SEVERITY_LEVEL_DEFAULT = 'notice';
const DISPLAY_MESSAGE_TYPE_DEFAULT = 'status';
protected $logger;
protected $currentUser;
protected $message = '';
protected $substitutions = [];
public function __construct(LoggerInterface $logger, AccountProxyInterface $current_user) {
$this->logger = $logger;
$this->currentUser = $current_user;
}
public function m($message, $substitutions = []) {
$this->message = $message;
$this->substitutions = $substitutions;
return $this;
}
public function log($logSeverityLevel = self::LOG_SEVERITY_LEVEL_DEFAULT) {
$this->logger
->{$logSeverityLevel}(strtr($this->message, $this->substitutions));
return $this;
}
public function display($displayMessageType = self::DISPLAY_MESSAGE_TYPE_DEFAULT, $permission = '') {
if (empty($permission) || $this->currentUser
->hasPermission($permission)) {
drupal_set_message($this
->t($this->message, $this->substitutions), $displayMessageType);
}
return $this;
}
}