mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-05 04:37:38 +02:00
Merge remote-tracking branch 'AntonAcc/speed-up-add-record' into main
This commit is contained in:
@@ -285,16 +285,18 @@ class Logger implements LoggerInterface, ResettableInterface
|
|||||||
*/
|
*/
|
||||||
public function addRecord(int $level, string $message, array $context = []): bool
|
public function addRecord(int $level, string $message, array $context = []): bool
|
||||||
{
|
{
|
||||||
// check if any handler will handle this message so we can return early and save cycles
|
$offset = 0;
|
||||||
$handlerKey = null;
|
foreach ($this->handlers as $handler) {
|
||||||
foreach ($this->handlers as $key => $handler) {
|
|
||||||
if ($handler->isHandling(['level' => $level])) {
|
if ($handler->isHandling(['level' => $level])) {
|
||||||
$handlerKey = $key;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $handlerKey) {
|
$offset++;
|
||||||
|
}
|
||||||
|
// cut off checked not handleable handlers
|
||||||
|
$remainedHandlers = array_slice($this->handlers, $offset);
|
||||||
|
|
||||||
|
if (!$remainedHandlers) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,18 +317,10 @@ class Logger implements LoggerInterface, ResettableInterface
|
|||||||
$record = $processor($record);
|
$record = $processor($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
// advance the array pointer to the first handler that will handle this record
|
foreach ($remainedHandlers as $handler) {
|
||||||
reset($this->handlers);
|
|
||||||
while ($handlerKey !== key($this->handlers)) {
|
|
||||||
next($this->handlers);
|
|
||||||
}
|
|
||||||
|
|
||||||
while ($handler = current($this->handlers)) {
|
|
||||||
if (true === $handler->handle($record)) {
|
if (true === $handler->handle($record)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
next($this->handlers);
|
|
||||||
}
|
}
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$this->handleException($e, $record);
|
$this->handleException($e, $record);
|
||||||
|
Reference in New Issue
Block a user