‪TYPO3CMS  10.4
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 {
32  public function ‪writeLog(‪LogRecord $record)
33  {
34  $levelName = strtoupper($record->‪getLevel());
35  $data = '';
36  $recordData = $record->‪getData();
37  if (!empty($recordData)) {
38  // According to PSR3 the exception-key may hold an \Exception
39  // Since json_encode() does not encode an exception, we run the _toString() here
40  if (isset($recordData['exception']) && $recordData['exception'] instanceof \‪Exception) {
41  $recordData['exception'] = (string)$recordData['exception'];
42  }
43  $data = '- ' . json_encode($recordData);
44  }
45  $message = sprintf(
46  'TYPO3 [%s] request="%s" component="%s": %s %s',
47  $levelName,
48  $record->‪getRequestId(),
49  $record->‪getComponent(),
50  $record->‪getMessage(),
51  $data
52  );
53  if (false === error_log($message)) {
54  throw new \RuntimeException('Could not write log record to PHP error log', 1345036336);
55  }
56  return $this;
57  }
58 }
‪TYPO3\CMS\Core\Log\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Core\Log\LogRecord\getData
‪array getData()
Definition: LogRecord.php:187
‪TYPO3\CMS\Core\Log\LogRecord\getLevel
‪string getLevel()
Definition: LogRecord.php:165
‪TYPO3\CMS\Core\Log\LogRecord
Definition: LogRecord.php:22
‪TYPO3\CMS\Core\Log\LogRecord\getMessage
‪string getMessage()
Definition: LogRecord.php:222
‪TYPO3\CMS\Core\Log\LogRecord\getComponent
‪string getComponent()
Definition: LogRecord.php:118
‪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\PhpErrorLogWriter
Definition: PhpErrorLogWriter.php:24
‪TYPO3\CMS\Core\Log\LogRecord\getRequestId
‪string getRequestId()
Definition: LogRecord.php:244