You are here

public function TextimageLogger::log in Textimage 8.3

Same name and namespace in other branches
  1. 8.4 src/TextimageLogger.php \Drupal\textimage\TextimageLogger::log()

Overrides LoggerChannel::log

File

src/TextimageLogger.php, line 51

Class

TextimageLogger
Defines a Textimage logger.

Namespace

Drupal\textimage

Code

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
    drupal_set_message($this
      ->t($message, $context), $type, FALSE);
  }
}