You are here

public function FileLog::log in File Log 8

Same name and namespace in other branches
  1. 2.0.x src/Logger/FileLog.php \Drupal\filelog\Logger\FileLog::log()

Overrides RfcLoggerTrait::log

File

src/Logger/FileLog.php, line 152

Class

FileLog
File-based logger.

Namespace

Drupal\filelog\Logger

Code

public function log($level, $message, array $context = []) : void {
  if (!$this
    ->shouldLog($level, $message, $context)) {
    return;
  }
  $entry = $this
    ->render($level, $message, $context);
  try {
    $this
      ->openFile();
    $this
      ->write($entry);
  } catch (FileLogException $error) {

    // Log the exception, unless we were already logging a filelog error.
    if ($context['channel'] !== 'filelog') {
      watchdog_exception('filelog', $error);
    }

    // Write the message directly to STDERR.
    fwrite($this
      ->stderr(), $entry . "\n");
  }
}