‪TYPO3CMS  ‪main
PhpErrorLogWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 
24 {
33  {
34  $data = '';
35  $context = ‪$record->getData();
36  $message = ‪$record->getMessage();
37  if (!empty($context)) {
38  // Fold an exception into the message, and string-ify it into context so it can be jsonified.
39  if (isset($context['exception']) && $context['exception'] instanceof \Throwable) {
40  $message .= $this->‪formatException($context['exception']);
41  $context['exception'] = (string)$context['exception'];
42  }
43  $data = '- ' . json_encode($context);
44  }
45 
46  $message = sprintf(
47  'TYPO3 [%s] request="%s" component="%s": %s %s',
48  strtoupper(‪$record->getLevel()),
49  ‪$record->getRequestId(),
50  ‪$record->getComponent(),
51  $this->interpolate($message, $context),
52  $data
53  );
54  if (error_log($message) === false) {
55  throw new \RuntimeException('Could not write log record to PHP error log', 1345036336);
56  }
57  return $this;
58  }
59 }
‪TYPO3\CMS\Core\Log\LogRecord
Definition: LogRecord.php:24
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Core\Log\Writer
Definition: AbstractWriter.php:16
‪TYPO3\CMS\Core\Log\Writer\PhpErrorLogWriter\writeLog
‪TYPO3 CMS Core Log Writer WriterInterface writeLog(LogRecord $record)
Definition: PhpErrorLogWriter.php:32
‪TYPO3\CMS\Core\Log\Writer\AbstractWriter
Definition: AbstractWriter.php:25
‪TYPO3\CMS\Core\Log\Writer\AbstractWriter\formatException
‪formatException(\Throwable $ex)
Definition: AbstractWriter.php:82
‪TYPO3\CMS\Core\Log\Writer\PhpErrorLogWriter
Definition: PhpErrorLogWriter.php:24