mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-07 21:56:31 +02:00
Simplify addRecord further by doing a single foreach over all handlers, refs #1489
This commit is contained in:
@@ -286,18 +286,13 @@ 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
|
||||||
{
|
{
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
|
$record = null;
|
||||||
|
|
||||||
foreach ($this->handlers as $handler) {
|
foreach ($this->handlers as $handler) {
|
||||||
if ($handler->isHandling(['level' => $level])) {
|
if (null === $record) {
|
||||||
break;
|
// skip creating the record as long as no handler is going to handle it
|
||||||
}
|
if (!$handler->isHandling(['level' => $level])) {
|
||||||
|
continue;
|
||||||
$offset++;
|
|
||||||
}
|
|
||||||
// cut off checked not handleable handlers
|
|
||||||
$remainedHandlers = array_slice($this->handlers, $offset);
|
|
||||||
|
|
||||||
if (!$remainedHandlers) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$levelName = static::getLevelName($level);
|
$levelName = static::getLevelName($level);
|
||||||
@@ -316,18 +311,29 @@ class Logger implements LoggerInterface, ResettableInterface
|
|||||||
foreach ($this->processors as $processor) {
|
foreach ($this->processors as $processor) {
|
||||||
$record = $processor($record);
|
$record = $processor($record);
|
||||||
}
|
}
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$this->handleException($e, $record);
|
||||||
|
|
||||||
foreach ($remainedHandlers as $handler) {
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// once the record exist, send it to all handlers as long as the bubbling chain is not interrupted
|
||||||
|
if (null !== $record) {
|
||||||
|
try {
|
||||||
if (true === $handler->handle($record)) {
|
if (true === $handler->handle($record)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$this->handleException($e, $record);
|
$this->handleException($e, $record);
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null !== $record;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends a log cycle and frees all resources used by handlers.
|
* Ends a log cycle and frees all resources used by handlers.
|
||||||
|
Reference in New Issue
Block a user