From 16bd650a8b74b98d2406bda83848b05798226670 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 595ad14cd..403a7fdfd 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -24,7 +24,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 ee86c834f..ca9d650b3 100644 --- a/lib/Listener/LogListener.php +++ b/lib/Listener/LogListener.php @@ -23,14 +23,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; }