diff --git a/src/Util/Logger/FriendicaProcessor.php b/src/Util/Logger/FriendicaIntrospectionProcessor.php similarity index 53% rename from src/Util/Logger/FriendicaProcessor.php rename to src/Util/Logger/FriendicaIntrospectionProcessor.php index 21c6fcc03..aa3933a21 100644 --- a/src/Util/Logger/FriendicaProcessor.php +++ b/src/Util/Logger/FriendicaIntrospectionProcessor.php @@ -11,28 +11,28 @@ use Monolog\Processor\ProcessorInterface; * Based on the class IntrospectionProcessor without the "class" information * @see IntrospectionProcessor */ -class FriendicaProcessor implements ProcessorInterface +class FriendicaIntrospectionProcessor implements ProcessorInterface { private $level; private $skipStackFramesCount; + private $skipClassesPartials; + private $skipFunctions = [ 'call_user_func', 'call_user_func_array', ]; - private $skipFiles = [ - 'Logger.php' - ]; - /** * @param string|int $level The minimum logging level at which this Processor will be triggered + * @param array $skipClassesPartials An array of classes to skip during logging * @param int $skipStackFramesCount If the logger should use information from other hierarchy levels of the call */ - public function __construct($level = Logger::DEBUG, $skipStackFramesCount = 0) + public function __construct($level = Logger::DEBUG, $skipClassesPartials = array(), $skipStackFramesCount = 0) { $this->level = Logger::toMonologLevel($level); + $this->skipClassesPartials = array_merge(array('Monolog\\'), $skipClassesPartials); $this->skipStackFramesCount = $skipStackFramesCount; } @@ -47,13 +47,12 @@ class FriendicaProcessor implements ProcessorInterface $i = 1; - // Skip everything that we shouldn't display - while (in_array($trace[$i]['function'], $this->skipFunctions) || - !isset($trace[$i - 1]['file']) || - in_array(basename($trace[$i - 1]['file']), $this->skipFiles)) { + while ($this->isTraceClassOrSkippedFunction($trace, $i)) { $i++; } + $i += $this->skipStackFramesCount; + // we should have the call source now $record['extra'] = array_merge( $record['extra'], @@ -66,4 +65,30 @@ class FriendicaProcessor implements ProcessorInterface return $record; } + + /** + * Checks if the current trace class or function has to be skipped + * + * @param array $trace The current trace array + * @param int $index The index of the current hierarchy level + * @return bool True if the class or function should get skipped, otherwise false + */ + private function isTraceClassOrSkippedFunction(array $trace, $index) + { + if (!isset($trace[$index])) { + return false; + } + + if (isset($trace[$index]['class'])) { + foreach ($this->skipClassesPartials as $part) { + if (strpos($trace[$index]['class'], $part) !== false) { + return true; + } + } + } elseif (in_array($trace[$index]['function'], $this->skipFunctions)) { + return true; + } + + return false; + } } diff --git a/src/Util/LoggerFactory.php b/src/Util/LoggerFactory.php index 88b6fe8c8..4d3a28716 100644 --- a/src/Util/LoggerFactory.php +++ b/src/Util/LoggerFactory.php @@ -4,7 +4,7 @@ namespace Friendica\Util; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\Logger\FriendicaDevelopHandler; -use Friendica\Util\Logger\FriendicaProcessor; +use Friendica\Util\Logger\FriendicaIntrospectionProcessor; use Monolog; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; @@ -28,7 +28,8 @@ class LoggerFactory $logger = new Monolog\Logger($channel); $logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor()); $logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor()); - $logger->pushProcessor(new FriendicaProcessor(LogLevel::DEBUG, 1)); + $logger->pushProcessor(new Monolog\Processor\UidProcessor()); + $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, ['Friendica\\Core\\Logger'])); return $logger; } @@ -51,7 +52,8 @@ class LoggerFactory $logger = new Monolog\Logger($channel); $logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor()); $logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor()); - $logger->pushProcessor(new FriendicaProcessor(LogLevel::DEBUG, 1)); + $logger->pushProcessor(new Monolog\Processor\UidProcessor()); + $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, ['Friendica\\Core\\Logger'])); $logger->pushHandler(new FriendicaDevelopHandler($developerIp));