TYPO3 CMS  TYPO3_8-7
DatabaseWriter.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  */
19 
24 {
30  protected $logTable = 'sys_log';
31 
38  public function setLogTable($tableName)
39  {
40  $this->logTable = $tableName;
41  return $this;
42  }
43 
49  public function getLogTable()
50  {
51  return $this->logTable;
52  }
53 
60  public function writeLog(LogRecord $record)
61  {
62  $data = '';
63  $recordData = $record->getData();
64  if (!empty($recordData)) {
65  // According to PSR3 the exception-key may hold an \Exception
66  // Since json_encode() does not encode an exception, we run the _toString() here
67  if (isset($recordData['exception']) && $recordData['exception'] instanceof \Exception) {
68  $recordData['exception'] = (string)$recordData['exception'];
69  }
70  $data = '- ' . json_encode($recordData);
71  }
72 
73  $fieldValues = [
74  'request_id' => $record->getRequestId(),
75  'time_micro' => $record->getCreated(),
76  'component' => $record->getComponent(),
77  'level' => $record->getLevel(),
78  'message' => $record->getMessage(),
79  'data' => $data
80  ];
81 
82  GeneralUtility::makeInstance(ConnectionPool::class)
83  ->getConnectionForTable($this->logTable)
84  ->insert($this->logTable, $fieldValues);
85 
86  return $this;
87  }
88 }
static makeInstance($className,... $constructorArguments)