diff options
author | Robin Appelman <robin@icewind.nl> | 2023-07-13 15:17:52 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2023-07-13 15:17:52 +0200 |
commit | 2fe50de13dc125f7ffbe881a96f0a1d99424eda8 (patch) | |
tree | 4c143fc247f0f0edf1e3aadf7062c479fa1e3d95 | |
parent | c5a6c7e0dd9666cc8c550b616d13118616f67779 (diff) | |
download | nextcloud-server-log-event-recursion.tar.gz nextcloud-server-log-event-recursion.zip |
prevent recursion with log eventslog-event-recursion
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | lib/private/Log.php | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php index 9aff774d0ec..eed3d88057a 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -210,6 +210,7 @@ class Log implements ILogger, IDataLogger { * @return void */ public function log(int $level, string $message, array $context = []) { + static $inLogEvent = false; $minLevel = $this->getLogLevel($context); array_walk($context, [$this->normalizer, 'format']); @@ -217,8 +218,13 @@ class Log implements ILogger, IDataLogger { $app = $context['app'] ?? 'no app in context'; $entry = $this->interpolateMessage($context, $message); - if ($this->eventDispatcher) { - $this->eventDispatcher->dispatchTyped(new BeforeMessageLoggedEvent($app, $level, $entry)); + if ($this->eventDispatcher && !$inLogEvent) { + $inLogEvent = true; + try { + $this->eventDispatcher->dispatchTyped(new BeforeMessageLoggedEvent($app, $level, $entry)); + } catch (Throwable $e) { + // ignore exceptions from inside the logger, as trying to log them would lead to recursion + } } try { |