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