TYPO3 CMS  TYPO3_7-6
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 }
static getName($level)
Definition: LogLevel.php:118