‪TYPO3CMS  9.5
IntrospectionProcessor.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 
18 
23 {
30  protected ‪$appendFullBackTrace = false;
31 
37  protected ‪$shiftBackTraceLevel = 0;
38 
44  private ‪$precedingBacktraceLine = '';
45 
51  private ‪$precedingBacktraceFile = '';
52 
60  {
61  $this->shiftBackTraceLevel = (int)‪$shiftBackTraceLevel;
62  return $this;
63  }
64 
72  {
73  $this->appendFullBackTrace = (bool)‪$appendFullBackTrace;
74  return $this;
75  }
76 
85  public function ‪processLogRecord(‪LogRecord $logRecord)
86  {
87  $trace = $this->‪getDebugBacktrace();
88 
89  // skip TYPO3\CMS\Core\Log classes
90  foreach ($trace as $traceEntry) {
91  if (isset($traceEntry['class']) && false !== strpos($traceEntry['class'], 'TYPO3\\CMS\\Core\\Log')) {
92  $trace = $this->‪shiftBacktraceLevel($trace);
93  } else {
94  break;
95  }
96  }
97 
98  // shift a given number of entries from the trace
99  for ($i = 0; $i < ‪$this->shiftBackTraceLevel; $i++) {
100  // shift only if afterwards there is at least one entry left after.
101  if (count($trace) > 1) {
102  $trace = $this->‪shiftBacktraceLevel($trace);
103  }
104  }
105 
106  if ($this->appendFullBackTrace) {
107  // Add the line and file of the last entry that has these information
108  // to the first backtrace entry if it does not have this information.
109  // This is required in case we have shifted entries and the first entry
110  // is now a call_user_func that does not contain the line and file information.
111  if (!isset($trace[0]['line'])) {
112  $trace[0] = ['line' => ‪$this->precedingBacktraceLine] + $trace[0];
113  }
114  if (!isset($trace[0]['file'])) {
115  $trace[0] = ['file' => ‪$this->precedingBacktraceFile] + $trace[0];
116  }
117 
118  $logRecord->‪addData([
119  'backtrace' => $trace
120  ]);
121  } else {
122  $logRecord->‪addData([
123  'file' => $trace[0]['file'] ?? null,
124  'line' => $trace[0]['line'] ?? null,
125  'class' => $trace[0]['class'] ?? null,
126  'function' => $trace[0]['function'] ?? null
127  ]);
128  }
129 
130  return $logRecord;
131  }
132 
139  protected function ‪shiftBacktraceLevel(array $backtrace)
140  {
141  if (isset($backtrace[0]['file'])) {
142  $this->precedingBacktraceFile = $backtrace[0]['file'];
143  }
144  if (isset($backtrace[0]['line'])) {
145  $this->precedingBacktraceLine = $backtrace[0]['line'];
146  }
147  array_shift($backtrace);
148 
149  return $backtrace;
150  }
151 
157  protected function ‪getDebugBacktrace()
158  {
159  return debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
160  }
161 }
‪TYPO3\CMS\Core\Log\LogRecord\addData
‪TYPO3 CMS Core Log LogRecord addData(array $data)
Definition: LogRecord.php:198
‪TYPO3\CMS\Core\Log\Processor
Definition: AbstractMemoryProcessor.php:2
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor\$shiftBackTraceLevel
‪int $shiftBackTraceLevel
Definition: IntrospectionProcessor.php:35
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor\$precedingBacktraceFile
‪string $precedingBacktraceFile
Definition: IntrospectionProcessor.php:47
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor\processLogRecord
‪LogRecord processLogRecord(LogRecord $logRecord)
Definition: IntrospectionProcessor.php:81
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor\shiftBacktraceLevel
‪array shiftBacktraceLevel(array $backtrace)
Definition: IntrospectionProcessor.php:135
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor\getDebugBacktrace
‪array getDebugBacktrace()
Definition: IntrospectionProcessor.php:153
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor
Definition: IntrospectionProcessor.php:23
‪TYPO3\CMS\Core\Log\LogRecord
Definition: LogRecord.php:21
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor\setShiftBackTraceLevel
‪IntrospectionProcessor setShiftBackTraceLevel($shiftBackTraceLevel)
Definition: IntrospectionProcessor.php:55
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor\$precedingBacktraceLine
‪string $precedingBacktraceLine
Definition: IntrospectionProcessor.php:41
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor\$appendFullBackTrace
‪bool $appendFullBackTrace
Definition: IntrospectionProcessor.php:29
‪TYPO3\CMS\Core\Log\Processor\AbstractProcessor
Definition: AbstractProcessor.php:23
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor\setAppendFullBackTrace
‪IntrospectionProcessor setAppendFullBackTrace($appendFullBackTrace)
Definition: IntrospectionProcessor.php:67