You are here

class ErrorLogMessageFormatter in Logging and alerts 8

Same name and namespace in other branches
  1. 2.0.x errorlog/src/Logger/ErrorLogMessageFormatter.php \Drupal\errorlog\Logger\ErrorLogMessageFormatter

Logger class for errorlog module.

Hierarchy

Expanded class hierarchy of ErrorLogMessageFormatter

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

File

errorlog/src/Logger/ErrorLogMessageFormatter.php, line 13

Namespace

Drupal\errorlog\Logger
View source
class ErrorLogMessageFormatter implements LoggerInterface {
  use RfcLoggerTrait;

  /**
   * Configuration object.
   *
   * @var \Drupal\Core\Config\Config
   */
  protected $config;

  /**
   * Renderer object.
   *
   * @var \Drupal\Core\Render\Renderer
   */
  protected $renderer;

  /**
   * Constructs a SysLog object.
   *
   * @param \Drupal\Core\Config\ConfigFactory $config_factory
   *   The configuration factory object.
   * @param \Drupal\Core\Render\Renderer $renderer
   *   The Renderer object.
   */
  public function __construct(ConfigFactory $config_factory, Renderer $renderer) {
    $this->config = $config_factory
      ->get('errorlog.settings');
    $this->renderer = $renderer;
  }

  /**
   * {@inheritdoc}
   */
  public function log($level, $message, array $context = []) {
    if ($this->config
      ->get('errorlog_' . $level)) {
      $log = [
        'level' => $level,
        'context' => $context,
        'message' => $message,
      ];

      // Send themed alert to the web server's log.
      if (\Drupal::hasService('theme.manager')) {
        $errorlog_theme_element = [
          '#theme' => 'errorlog_format',
          '#log' => $log,
        ];
        $message = $this->renderer
          ->renderPlain($errorlog_theme_element);
      }
      error_log($message, 0);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ErrorLogMessageFormatter::$config protected property Configuration object.
ErrorLogMessageFormatter::$renderer protected property Renderer object.
ErrorLogMessageFormatter::log public function Logs with an arbitrary level. Overrides RfcLoggerTrait::log
ErrorLogMessageFormatter::__construct public function Constructs a SysLog object.
RfcLoggerTrait::alert public function
RfcLoggerTrait::critical public function
RfcLoggerTrait::debug public function
RfcLoggerTrait::emergency public function
RfcLoggerTrait::error public function
RfcLoggerTrait::info public function
RfcLoggerTrait::notice public function
RfcLoggerTrait::warning public function