‪TYPO3CMS  9.5
PhpErrorLogWriter.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
18 
23 {
31  public function ‪writeLog(‪LogRecord $record)
32  {
33  $levelName = ‪LogLevel::getName($record->‪getLevel());
34  $data = '';
35  $recordData = $record->‪getData();
36  if (!empty($recordData)) {
37  // According to PSR3 the exception-key may hold an \Exception
38  // Since json_encode() does not encode an exception, we run the _toString() here
39  if (isset($recordData['exception']) && $recordData['exception'] instanceof \‪Exception) {
40  $recordData['exception'] = (string)$recordData['exception'];
41  }
42  $data = '- ' . json_encode($recordData);
43  }
44  $message = sprintf(
45  'TYPO3 [%s] request="%s" component="%s": %s %s',
46  $levelName,
47  $record->‪getRequestId(),
48  $record->‪getComponent(),
49  $record->‪getMessage(),
50  $data
51  );
52  if (false === error_log($message)) {
53  throw new \RuntimeException('Could not write log record to PHP error log', 1345036336);
54  }
55  return $this;
56  }
57 }
‪TYPO3\CMS\Core\Log\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Log\LogRecord\getData
‪array getData()
Definition: LogRecord.php:186
‪TYPO3\CMS\Core\Log\LogRecord
Definition: LogRecord.php:21
‪TYPO3\CMS\Core\Log\LogRecord\getMessage
‪string getMessage()
Definition: LogRecord.php:221
‪TYPO3\CMS\Core\Log\LogRecord\getComponent
‪string getComponent()
Definition: LogRecord.php:117
‪TYPO3\CMS\Core\Log\Writer
Definition: AbstractWriter.php:2
‪TYPO3\CMS\Core\Log\Writer\PhpErrorLogWriter\writeLog
‪TYPO3 CMS Core Log Writer WriterInterface writeLog(LogRecord $record)
Definition: PhpErrorLogWriter.php:31
‪TYPO3\CMS\Core\Log\Writer\AbstractWriter
Definition: AbstractWriter.php:24
‪TYPO3\CMS\Core\Log\LogLevel\getName
‪static string getName($level)
Definition: LogLevel.php:117
‪TYPO3\CMS\Core\Log\Writer\PhpErrorLogWriter
Definition: PhpErrorLogWriter.php:23
‪TYPO3\CMS\Core\Log\LogRecord\getLevel
‪int getLevel()
Definition: LogRecord.php:164
‪TYPO3\CMS\Core\Log\LogRecord\getRequestId
‪string getRequestId()
Definition: LogRecord.php:243
‪TYPO3\CMS\Core\Log\LogLevel
Definition: LogLevel.php:21