TYPO3 CMS  TYPO3_7-6
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  */
17 
22 {
28  protected $logTable = 'sys_log';
29 
36  public function setLogTable($tableName)
37  {
38  $this->logTable = $tableName;
39  return $this;
40  }
41 
47  public function getLogTable()
48  {
49  return $this->logTable;
50  }
51 
59  public function writeLog(LogRecord $record)
60  {
61  $data = '';
62  $recordData = $record->getData();
63  if (!empty($recordData)) {
64  // According to PSR3 the exception-key may hold an \Exception
65  // Since json_encode() does not encode an exception, we run the _toString() here
66  if (isset($recordData['exception']) && $recordData['exception'] instanceof \Exception) {
67  $recordData['exception'] = (string)$recordData['exception'];
68  }
69  $data = '- ' . json_encode($recordData);
70  }
71 
72  $fieldValues = [
73  'request_id' => $record->getRequestId(),
74  'time_micro' => $record->getCreated(),
75  'component' => $record->getComponent(),
76  'level' => $record->getLevel(),
77  'message' => $record->getMessage(),
78  'data' => $data
79  ];
80 
81  if (false === $this->getDatabaseConnection()->exec_INSERTquery($this->logTable, $fieldValues)) {
82  throw new \RuntimeException('Could not write log record to database', 1345036334);
83  }
84  return $this;
85  }
86 
90  protected function getDatabaseConnection()
91  {
92  return $GLOBALS['TYPO3_DB'];
93  }
94 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']