class ErrorLogMessageFormatter in Logging and alerts 8
Same name and namespace in other branches
- 2.0.x errorlog/src/Logger/ErrorLogMessageFormatter.php \Drupal\errorlog\Logger\ErrorLogMessageFormatter
Logger class for errorlog module.
Hierarchy
- class \Drupal\errorlog\Logger\ErrorLogMessageFormatter implements \Psr\Log\LoggerInterface uses RfcLoggerTrait
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
File
- errorlog/src/ Logger/ ErrorLogMessageFormatter.php, line 13 
Namespace
Drupal\errorlog\LoggerView 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
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| ErrorLogMessageFormatter:: | protected | property | Configuration object. | |
| ErrorLogMessageFormatter:: | protected | property | Renderer object. | |
| ErrorLogMessageFormatter:: | public | function | Logs with an arbitrary level. Overrides RfcLoggerTrait:: | |
| ErrorLogMessageFormatter:: | public | function | Constructs a SysLog object. | |
| RfcLoggerTrait:: | public | function | ||
| RfcLoggerTrait:: | public | function | ||
| RfcLoggerTrait:: | public | function | ||
| RfcLoggerTrait:: | public | function | ||
| RfcLoggerTrait:: | public | function | ||
| RfcLoggerTrait:: | public | function | ||
| RfcLoggerTrait:: | public | function | ||
| RfcLoggerTrait:: | public | function | 
