‪TYPO3CMS  10.4
DatabaseWriter.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 
22 
27 {
33  protected ‪$logTable = 'sys_log';
34 
41  public function ‪setLogTable($tableName)
42  {
43  $this->logTable = $tableName;
44  return $this;
45  }
46 
52  public function ‪getLogTable()
53  {
54  return ‪$this->logTable;
55  }
56 
63  public function ‪writeLog(‪LogRecord $record)
64  {
65  $data = '';
66  $recordData = $record->‪getData();
67  if (!empty($recordData)) {
68  // According to PSR3 the exception-key may hold an \Exception
69  // Since json_encode() does not encode an exception, we run the _toString() here
70  if (isset($recordData['exception']) && $recordData['exception'] instanceof \‪Exception) {
71  $recordData['exception'] = (string)$recordData['exception'];
72  }
73  $data = '- ' . json_encode($recordData);
74  }
75 
76  $fieldValues = [
77  'request_id' => $record->‪getRequestId(),
78  'time_micro' => $record->‪getCreated(),
79  'component' => $record->‪getComponent(),
80  'level' => ‪LogLevel::normalizeLevel($record->‪getLevel()),
81  'message' => $record->‪getMessage(),
82  'data' => $data
83  ];
84 
85  GeneralUtility::makeInstance(ConnectionPool::class)
86  ->getConnectionForTable($this->logTable)
87  ->insert($this->logTable, $fieldValues);
88 
89  return $this;
90  }
91 }
‪TYPO3\CMS\Core\Log\Writer\DatabaseWriter
Definition: DatabaseWriter.php:27
‪TYPO3\CMS\Core\Log\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Core\Log\Writer\DatabaseWriter\$logTable
‪string $logTable
Definition: DatabaseWriter.php:32
‪TYPO3\CMS\Core\Log\Writer\DatabaseWriter\setLogTable
‪TYPO3 CMS Core Log Writer AbstractWriter setLogTable($tableName)
Definition: DatabaseWriter.php:40
‪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\DatabaseWriter\getLogTable
‪string getLogTable()
Definition: DatabaseWriter.php:51
‪TYPO3\CMS\Core\Log\Writer
Definition: AbstractWriter.php:16
‪TYPO3\CMS\Core\Log\Writer\DatabaseWriter\writeLog
‪TYPO3 CMS Core Log Writer WriterInterface writeLog(LogRecord $record)
Definition: DatabaseWriter.php:62
‪TYPO3\CMS\Core\Log\Writer\AbstractWriter
Definition: AbstractWriter.php:25
‪TYPO3\CMS\Core\Log\LogRecord\getCreated
‪float getCreated()
Definition: LogRecord.php:140
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Log\LogLevel\normalizeLevel
‪static int normalizeLevel($level)
Definition: LogLevel.php:94
‪TYPO3\CMS\Core\Log\LogRecord\getRequestId
‪string getRequestId()
Definition: LogRecord.php:244
‪TYPO3\CMS\Core\Log\LogLevel
Definition: LogLevel.php:24