‪TYPO3CMS  9.5
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 }
‪TYPO3\CMS\Core\Log\Writer\DatabaseWriter
Definition: DatabaseWriter.php:24
‪TYPO3\CMS\Core\Log\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Log\Writer\DatabaseWriter\$logTable
‪string $logTable
Definition: DatabaseWriter.php:29
‪TYPO3\CMS\Core\Log\Writer\DatabaseWriter\setLogTable
‪TYPO3 CMS Core Log Writer AbstractWriter setLogTable($tableName)
Definition: DatabaseWriter.php:37
‪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\DatabaseWriter\getLogTable
‪string getLogTable()
Definition: DatabaseWriter.php:48
‪TYPO3\CMS\Core\Log\Writer
Definition: AbstractWriter.php:2
‪TYPO3\CMS\Core\Log\Writer\DatabaseWriter\writeLog
‪TYPO3 CMS Core Log Writer WriterInterface writeLog(LogRecord $record)
Definition: DatabaseWriter.php:59
‪TYPO3\CMS\Core\Log\Writer\AbstractWriter
Definition: AbstractWriter.php:24
‪TYPO3\CMS\Core\Log\LogRecord\getCreated
‪float getCreated()
Definition: LogRecord.php:139
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Log\LogRecord\getLevel
‪int getLevel()
Definition: LogRecord.php:164
‪TYPO3\CMS\Core\Log\LogRecord\getRequestId
‪string getRequestId()
Definition: LogRecord.php:243