From 4fa355a5f9a394495e55c5b6d1b8a4bef3fbc3e5 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Wed, 26 Mar 2025 11:01:04 +0100 Subject: [PATCH] fix: Do not register listener when not in console Registering the listener no matter what defeats the perf optimisation done here: https://github.com/nextcloud/server/blob/cb7c82c13d5d6cf0b21b4499365460c605936c5a/lib/private/Log.php#L331-L337 Signed-off-by: Louis Chemineau --- lib/AppInfo/Application.php | 4 +++- lib/Listener/LogListener.php | 12 ++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 7961ea753..2716d3197 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -39,7 +39,9 @@ public function __construct(array $urlParams = []) { } public function register(IRegistrationContext $context): void { - $context->registerEventListener(BeforeMessageLoggedEvent::class, LogListener::class); + if (defined('OC_CONSOLE') && \OC_CONSOLE) { + $context->registerEventListener(BeforeMessageLoggedEvent::class, LogListener::class); + } $context->registerService(Formatter::class, function (ContainerInterface $c) { return new Formatter(\OC::$SERVERROOT); }); diff --git a/lib/Listener/LogListener.php b/lib/Listener/LogListener.php index 8d291f752..af63bf4fb 100644 --- a/lib/Listener/LogListener.php +++ b/lib/Listener/LogListener.php @@ -38,14 +38,10 @@ class LogListener implements IEventListener { private ?Console $console; public function __construct(Formatter $formatter, SystemConfig $config) { - if (defined('OC_CONSOLE') && \OC_CONSOLE) { - $level = getenv('OCC_LOG'); - if ($level) { - $terminal = new Terminal(); - $this->console = new Console($formatter, $config, $level, $terminal->getWidth()); - } else { - $this->console = null; - } + $level = getenv('OCC_LOG'); + if ($level) { + $terminal = new Terminal(); + $this->console = new Console($formatter, $config, $level, $terminal->getWidth()); } else { $this->console = null; }