class TextimageLogger in Textimage 8.4
Same name and namespace in other branches
- 8.3 src/TextimageLogger.php \Drupal\textimage\TextimageLogger
Defines a Textimage logger.
Hierarchy
- class \Drupal\Core\Logger\LoggerChannel implements LoggerChannelInterface uses \Psr\Log\LoggerTrait
- class \Drupal\textimage\TextimageLogger uses MessengerTrait, StringTranslationTrait
Expanded class hierarchy of TextimageLogger
1 string reference to 'TextimageLogger'
1 service uses TextimageLogger
File
- src/
TextimageLogger.php, line 16
Namespace
Drupal\textimageView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LoggerChannel:: |
protected | property | Number of times LoggerChannel::log() has been called for a single message. | |
LoggerChannel:: |
protected | property | The name of the channel of this logger instance. | |
LoggerChannel:: |
protected | property | The current user object. | |
LoggerChannel:: |
protected | property | Map of PSR3 log constants to RFC 5424 log constants. | |
LoggerChannel:: |
protected | property | An array of arrays of \Psr\Log\LoggerInterface keyed by priority. | |
LoggerChannel:: |
protected | property | The request stack object. | |
LoggerChannel:: |
public | function |
Adds a logger. Overrides LoggerChannelInterface:: |
|
LoggerChannel:: |
constant | Maximum call depth to self::log() for a single log message. | ||
LoggerChannel:: |
public | function |
Sets the current user. Overrides LoggerChannelInterface:: |
|
LoggerChannel:: |
public | function |
Sets the loggers for this channel. Overrides LoggerChannelInterface:: |
|
LoggerChannel:: |
public | function |
Sets the request stack. Overrides LoggerChannelInterface:: |
|
LoggerChannel:: |
protected | function | Sorts loggers according to priority. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TextimageLogger:: |
protected | property | The configuration factory. | |
TextimageLogger:: |
protected | property | The Textimage logger channel. | |
TextimageLogger:: |
public | function |
Logs with an arbitrary level. Overrides LoggerChannel:: |
|
TextimageLogger:: |
public | function |
Constructs a TextimageLogger object. Overrides LoggerChannel:: |