mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-04 12:17:35 +02:00
Add a way to disable logging loop detection, closes #1681
This commit is contained in:
@@ -152,6 +152,13 @@ class Logger implements LoggerInterface, ResettableInterface
|
|||||||
*/
|
*/
|
||||||
private $logDepth = 0;
|
private $logDepth = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool Whether to detect infinite logging loops
|
||||||
|
*
|
||||||
|
* This can be disabled via {@see useLoggingLoopDetection} if you have async handlers that do not play well with this
|
||||||
|
*/
|
||||||
|
private $detectCycles = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @psalm-param array<callable(array): array> $processors
|
* @psalm-param array<callable(array): array> $processors
|
||||||
*
|
*
|
||||||
@@ -284,6 +291,13 @@ class Logger implements LoggerInterface, ResettableInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function useLoggingLoopDetection(bool $detectCycles): self
|
||||||
|
{
|
||||||
|
$this->detectCycles = $detectCycles;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a log record.
|
* Adds a log record.
|
||||||
*
|
*
|
||||||
@@ -296,7 +310,9 @@ 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
|
||||||
{
|
{
|
||||||
|
if ($this->detectCycles) {
|
||||||
$this->logDepth += 1;
|
$this->logDepth += 1;
|
||||||
|
}
|
||||||
if ($this->logDepth === 3) {
|
if ($this->logDepth === 3) {
|
||||||
$this->warning('A possible infinite logging loop was detected and aborted. It appears some of your handler code is triggering logging, see the previous log record for a hint as to what may be the cause.');
|
$this->warning('A possible infinite logging loop was detected and aborted. It appears some of your handler code is triggering logging, see the previous log record for a hint as to what may be the cause.');
|
||||||
return false;
|
return false;
|
||||||
@@ -349,8 +365,10 @@ class Logger implements LoggerInterface, ResettableInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
if ($this->detectCycles) {
|
||||||
$this->logDepth--;
|
$this->logDepth--;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null !== $record;
|
return null !== $record;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user