ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Processor\IntrospectionProcessor Class Reference

Injects line/file:class/function where the log message came from. More...

+ Inheritance diagram for Monolog\Processor\IntrospectionProcessor:
+ Collaboration diagram for Monolog\Processor\IntrospectionProcessor:

Public Member Functions

 __construct ($level=Logger::DEBUG, array $skipClassesPartials=array(), $skipStackFramesCount=0)
 
 __invoke (array $record)
 

Private Member Functions

 isTraceClassOrSkippedFunction (array $trace, $index)
 

Private Attributes

 $level
 
 $skipClassesPartials
 
 $skipStackFramesCount
 
 $skipFunctions
 

Detailed Description

Injects line/file:class/function where the log message came from.

Warning: This only works if the handler processes the logs directly. If you put the processor on a handler that is behind a FingersCrossedHandler for example, the processor will only be called once the trigger level is reached, and all the log records will have the same file/line/.. data from the call that triggered the FingersCrossedHandler.

Author
Jordi Boggiano j.bog.nosp@m.gian.nosp@m.o@sel.nosp@m.d.be

Definition at line 27 of file IntrospectionProcessor.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Processor\IntrospectionProcessor::__construct (   $level = Logger::DEBUG,
array  $skipClassesPartials = array(),
  $skipStackFramesCount = 0 
)

Definition at line 40 of file IntrospectionProcessor.php.

References Monolog\Processor\IntrospectionProcessor\$level, Monolog\Processor\IntrospectionProcessor\$skipClassesPartials, Monolog\Processor\IntrospectionProcessor\$skipStackFramesCount, and Monolog\Logger\toMonologLevel().

41  {
42  $this->level = Logger::toMonologLevel($level);
43  $this->skipClassesPartials = array_merge(array('Monolog\\'), $skipClassesPartials);
44  $this->skipStackFramesCount = $skipStackFramesCount;
45  }
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:528
+ Here is the call graph for this function:

Member Function Documentation

◆ __invoke()

Monolog\Processor\IntrospectionProcessor::__invoke ( array  $record)
Parameters
array$record
Returns
array

Implements Monolog\Processor\ProcessorInterface.

Definition at line 51 of file IntrospectionProcessor.php.

References $i, Monolog\Processor\IntrospectionProcessor\$skipStackFramesCount, and Monolog\Processor\IntrospectionProcessor\isTraceClassOrSkippedFunction().

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  }
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:

◆ isTraceClassOrSkippedFunction()

Monolog\Processor\IntrospectionProcessor::isTraceClassOrSkippedFunction ( array  $trace,
  $index 
)
private

Definition at line 104 of file IntrospectionProcessor.php.

References $index.

Referenced by Monolog\Processor\IntrospectionProcessor\__invoke().

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  }
$index
Definition: metadata.php:60
+ Here is the caller graph for this function:

Field Documentation

◆ $level

Monolog\Processor\IntrospectionProcessor::$level
private

◆ $skipClassesPartials

Monolog\Processor\IntrospectionProcessor::$skipClassesPartials
private

◆ $skipFunctions

Monolog\Processor\IntrospectionProcessor::$skipFunctions
private
Initial value:
= array(
'call_user_func',
'call_user_func_array',
)

Definition at line 35 of file IntrospectionProcessor.php.

◆ $skipStackFramesCount

Monolog\Processor\IntrospectionProcessor::$skipStackFramesCount
private

The documentation for this class was generated from the following file: