TYPO3 CMS  TYPO3_8-7
ListSysLogCommand.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  */
16 
24 
29 class ListSysLogCommand extends Command
30 {
31 
35  public function configure()
36  {
37  $this->setDescription('Show entries from the sys_log database table of the last 24 hours.');
38  $this->setHelp('Prints a list of recent sys_log entries.' . LF . 'If you want to get more detailed information, use the --verbose option.');
39  }
40 
47  protected function execute(InputInterface $input, OutputInterface $output)
48  {
49  $io = new SymfonyStyle($input, $output);
50  $io->title($this->getDescription());
51  $showDetails = $output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL;
52 
53  $tableHeaders = [
54  'Log ID',
55  'Date & Time',
56  'User ID',
57  'Message'
58  ];
59  if ($showDetails) {
60  $tableHeaders[] = 'Details';
61  }
62 
63  // Initialize result array
64  $content = [];
65 
66  // Select DB relations from reference table
67  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_log');
68  $rowIterator = $queryBuilder
69  ->select('*')
70  ->from('sys_log')
71  ->where(
72  $queryBuilder->expr()->gt(
73  'tstamp',
74  $queryBuilder->createNamedParameter($GLOBALS['EXEC_TIME'] - 24 * 3600, \PDO::PARAM_INT)
75  )
76  )
77  ->orderBy('tstamp', 'DESC')
78  ->execute();
79 
80  while ($row = $rowIterator->fetch()) {
81  $logData = unserialize($row['log_data']);
82  $userInformation = $row['userid'];
83  if (!empty($logData['originalUser'])) {
84  $userInformation .= ' via ' . $logData['originalUser'];
85  }
86 
87  $result = [
88  $row['uid'],
89  BackendUtility::datetime($row['tstamp']),
90  $userInformation,
91  sprintf($row['details'], $logData[0], $logData[1], $logData[2], $logData[3], $logData[4], $logData[5])
92  ];
93 
94  if ($showDetails) {
95  $result[] = str_replace('; ', LF, GeneralUtility::arrayToLogString($row, [
96  'uid',
97  'userid',
98  'action',
99  'recuid',
100  'tablename',
101  'recpid',
102  'error',
103  'tstamp',
104  'type',
105  'details_nr',
106  'IP',
107  'event_pid',
108  'NEWid',
109  'workspace'
110  ]));
111  }
112  $content[] = $result;
113  }
114  $io->table($tableHeaders, $content);
115  }
116 }
static arrayToLogString(array $arr, $valueList=[], $valueLength=20)
static makeInstance($className,... $constructorArguments)
execute(InputInterface $input, OutputInterface $output)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']