3 namespace Friendica\Util\Logger;
6 use Monolog\Processor\ProcessorInterface;
9 * Injects line/file//function where the log message came from
11 * Based on the class IntrospectionProcessor without the "class" information
12 * @see IntrospectionProcessor
14 class FriendicaIntrospectionProcessor implements ProcessorInterface
18 private $skipStackFramesCount;
20 private $skipClassesPartials;
22 private $skipFunctions = [
24 'call_user_func_array',
28 * @param string|int $level The minimum logging level at which this Processor will be triggered
29 * @param array $skipClassesPartials An array of classes to skip during logging
30 * @param int $skipStackFramesCount If the logger should use information from other hierarchy levels of the call
32 public function __construct($level = Logger::DEBUG, $skipClassesPartials = array(), $skipStackFramesCount = 0)
34 $this->level = Logger::toMonologLevel($level);
35 $this->skipClassesPartials = array_merge(array('Monolog\\'), $skipClassesPartials);
36 $this->skipStackFramesCount = $skipStackFramesCount;
39 public function __invoke(array $record)
41 // return if the level is not high enough
42 if ($record['level'] < $this->level) {
46 $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
50 while ($this->isTraceClassOrSkippedFunction($trace, $i)) {
54 $i += $this->skipStackFramesCount;
56 // we should have the call source now
57 $record['extra'] = array_merge(
60 'file' => isset($trace[$i - 1]['file']) ? basename($trace[$i - 1]['file']) : null,
61 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null,
62 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null,
70 * Checks if the current trace class or function has to be skipped
72 * @param array $trace The current trace array
73 * @param int $index The index of the current hierarchy level
74 * @return bool True if the class or function should get skipped, otherwise false
76 private function isTraceClassOrSkippedFunction(array $trace, $index)
78 if (!isset($trace[$index])) {
82 if (isset($trace[$index]['class'])) {
83 foreach ($this->skipClassesPartials as $part) {
84 if (strpos($trace[$index]['class'], $part) !== false) {
88 } elseif (in_array($trace[$index]['function'], $this->skipFunctions)) {