ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
59 
60  // skip first since it's always the current method
61  array_shift($trace);
62  // the call_user_func call is also skipped
63  array_shift($trace);
64 
65  $i = 0;
66 
67  while ($this->isTraceClassOrSkippedFunction($trace, $i)) {
68  if (isset($trace[$i]['class'])) {
69  foreach ($this->skipClassesPartials as $part) {
70  if (strpos($trace[$i]['class'], $part) !== false) {
71  $i++;
72  continue 2;
73  }
74  }
75  } elseif (in_array($trace[$i]['function'], $this->skipFunctions)) {
76  $i++;
77  continue;
78  }
79 
80  break;
81  }
82 
84 
85  // we should have the call source now
86  $record['extra'] = array_merge(
87  $record['extra'],
88  array(
89  'file' => isset($trace[$i - 1]['file']) ? $trace[$i - 1]['file'] : null,
90  'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null,
91  'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : null,
92  'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null,
93  )
94  );
95 
96  return $record;
97  }
98 
99  private function isTraceClassOrSkippedFunction(array $trace, $index)
100  {
101  if (!isset($trace[$index])) {
102  return false;
103  }
104 
105  return isset($trace[$index]['class']) || in_array($trace[$index]['function'], $this->skipFunctions);
106  }
107 }
Injects line/file:class/function where the log message came from.
const DEBUG
Detailed debug information.
Definition: Logger.php:32
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:473
Create styles array
The data for the language used.
__construct($level=Logger::DEBUG, array $skipClassesPartials=array(), $skipStackFramesCount=0)