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 FriendicaProcessor implements ProcessorInterface
18 private $skipStackFramesCount;
20 private $skipFunctions = [
22 'call_user_func_array',
25 private $skipFiles = [
30 * @param string|int $level The minimum logging level at which this Processor will be triggered
31 * @param int $skipStackFramesCount If the logger should use information from other hierarchy levels of the call
33 public function __construct($level = Logger::DEBUG, $skipStackFramesCount = 0)
35 $this->level = Logger::toMonologLevel($level);
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 // Skip everything that we shouldn't display
51 while (in_array($trace[$i]['function'], $this->skipFunctions) ||
52 !isset($trace[$i - 1]['file']) ||
53 in_array(basename($trace[$i - 1]['file']), $this->skipFiles)) {
57 // we should have the call source now
58 $record['extra'] = array_merge(
61 'file' => isset($trace[$i - 1]['file']) ? basename($trace[$i - 1]['file']) : null,
62 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null,
63 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null,