ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
IntrospectionProcessor.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Monolog package.
5  *
6  * (c) Jordi Boggiano <j.boggiano@seld.be>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Monolog\Processor;
13 
14 use Monolog\Logger;
15 
28 {
29  private $level;
30 
32 
34 
35  private $skipFunctions = array(
36  'call_user_func',
37  'call_user_func_array',
38  );
39 
41  {
42  $this->level = Logger::toMonologLevel($level);
43  $this->skipClassesPartials = array_merge(array('Monolog\\'), $skipClassesPartials);
44  $this->skipStackFramesCount = $skipStackFramesCount;
45  }
46 
51  public function __invoke(array $record)
52  {
53  // return if the level is not high enough
54  if ($record['level'] < $this->level) {
55  return $record;
56  }
57 
58  /*
59  * http://php.net/manual/en/function.debug-backtrace.php
60  * As of 5.3.6, DEBUG_BACKTRACE_IGNORE_ARGS option was added.
61  * Any version less than 5.3.6 must use the DEBUG_BACKTRACE_IGNORE_ARGS constant value '2'.
62  */
63  $trace = debug_backtrace((PHP_VERSION_ID < 50306) ? 2 : DEBUG_BACKTRACE_IGNORE_ARGS);
64 
65  // skip first since it's always the current method
66  array_shift($trace);
67  // the call_user_func call is also skipped
68  array_shift($trace);
69 
70  $i = 0;
71 
72  while ($this->isTraceClassOrSkippedFunction($trace, $i)) {
73  if (isset($trace[$i]['class'])) {
74  foreach ($this->skipClassesPartials as $part) {
75  if (strpos($trace[$i]['class'], $part) !== false) {
76  $i++;
77  continue 2;
78  }
79  }
80  } elseif (in_array($trace[$i]['function'], $this->skipFunctions)) {
81  $i++;
82  continue;
83  }
84 
85  break;
86  }
87 
89 
90  // we should have the call source now
91  $record['extra'] = array_merge(
92  $record['extra'],
93  array(
94  'file' => isset($trace[$i - 1]['file']) ? $trace[$i - 1]['file'] : null,
95  'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null,
96  'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : null,
97  'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null,
98  )
99  );
100 
101  return $record;
102  }
103 
104  private function isTraceClassOrSkippedFunction(array $trace, $index)
105  {
106  if (!isset($trace[$index])) {
107  return false;
108  }
109 
110  return isset($trace[$index]['class']) || in_array($trace[$index]['function'], $this->skipFunctions);
111  }
112 }
Injects line/file:class/function where the log message came from.
const DEBUG
Detailed debug information.
Definition: Logger.php:33
$index
Definition: metadata.php:60
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:528
$i
Definition: disco.tpl.php:19
__construct($level=Logger::DEBUG, array $skipClassesPartials=array(), $skipStackFramesCount=0)
An optional interface to allow labelling Monolog processors.