Logger Unique ID

This commit is contained in:
Philipp Holzer 2019-01-28 11:21:48 +01:00
parent 0872fe746a
commit a5e12f53e8
No known key found for this signature in database
GPG Key ID: 517BE60E2CE5C8A5
2 changed files with 34 additions and 12 deletions

View File

@ -17,22 +17,22 @@ class FriendicaProcessor implements ProcessorInterface
private $skipStackFramesCount; private $skipStackFramesCount;
private $skipClassesPartials;
private $skipFunctions = [ private $skipFunctions = [
'call_user_func', 'call_user_func',
'call_user_func_array', 'call_user_func_array',
]; ];
private $skipFiles = [
'Logger.php'
];
/** /**
* @param string|int $level The minimum logging level at which this Processor will be triggered * @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 * @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, array $skipClassesPartials = array(), $skipStackFramesCount = 0)
{ {
$this->level = Logger::toMonologLevel($level); $this->level = Logger::toMonologLevel($level);
$this->skipClassesPartials = array_merge(array('Monolog\\'), $skipClassesPartials);
$this->skipStackFramesCount = $skipStackFramesCount; $this->skipStackFramesCount = $skipStackFramesCount;
} }
@ -47,13 +47,24 @@ class FriendicaProcessor implements ProcessorInterface
$i = 1; $i = 1;
// Skip everything that we shouldn't display while ($this->isTraceClassOrSkippedFunction($trace, $i)) {
while (in_array($trace[$i]['function'], $this->skipFunctions) || if (isset($trace[$i]['class'])) {
!isset($trace[$i - 1]['file']) || foreach ($this->skipClassesPartials as $part) {
in_array(basename($trace[$i - 1]['file']), $this->skipFiles)) { if (strpos($trace[$i]['class'], $part) !== false) {
$i++; $i++;
continue 2;
}
}
} elseif (in_array($trace[$i]['function'], $this->skipFunctions)) {
$i++;
continue;
}
break;
} }
$i += $this->skipStackFramesCount;
// we should have the call source now // we should have the call source now
$record['extra'] = array_merge( $record['extra'] = array_merge(
$record['extra'], $record['extra'],
@ -66,4 +77,13 @@ class FriendicaProcessor implements ProcessorInterface
return $record; return $record;
} }
private function isTraceClassOrSkippedFunction(array $trace, $index)
{
if (!isset($trace[$index])) {
return false;
}
return isset($trace[$index]['class']) || in_array($trace[$index]['function'], $this->skipFunctions);
}
} }

View File

@ -28,7 +28,8 @@ class LoggerFactory
$logger = new Monolog\Logger($channel); $logger = new Monolog\Logger($channel);
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor()); $logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor()); $logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
$logger->pushProcessor(new FriendicaProcessor(LogLevel::DEBUG, 1)); $logger->pushProcessor(new Monolog\Processor\UidProcessor());
$logger->pushProcessor(new FriendicaProcessor(LogLevel::DEBUG, ['Friendica\Core\Logger']));
return $logger; return $logger;
} }
@ -51,7 +52,8 @@ class LoggerFactory
$logger = new Monolog\Logger($channel); $logger = new Monolog\Logger($channel);
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor()); $logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor()); $logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
$logger->pushProcessor(new FriendicaProcessor(LogLevel::DEBUG, 1)); $logger->pushProcessor(new Monolog\Processor\UidProcessor());
$logger->pushProcessor(new FriendicaProcessor(LogLevel::DEBUG, ['Friendica\Core\Logger']));
$logger->pushHandler(new FriendicaDevelopHandler($developerIp)); $logger->pushHandler(new FriendicaDevelopHandler($developerIp));