Skip to content

Commit 5062634

Browse files
committed
fix: Do not register listener when not in console
Registering the listener no matter what, defits the perf optimisation done here: https://github.com/nextcloud/server/blob/cb7c82c13d5d6cf0b21b4499365460c605936c5a/lib/private/Log.php#L331-L337 Signed-off-by: Louis Chemineau <[email protected]>
1 parent 51c262a commit 5062634

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

lib/AppInfo/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public function __construct(array $urlParams = []) {
2424
}
2525

2626
public function register(IRegistrationContext $context): void {
27-
$context->registerEventListener(BeforeMessageLoggedEvent::class, LogListener::class);
27+
if (defined('OC_CONSOLE') && \OC_CONSOLE) {
28+
$context->registerEventListener(BeforeMessageLoggedEvent::class, LogListener::class);
29+
}
2830
$context->registerService(Formatter::class, function (ContainerInterface $c) {
2931
return new Formatter(\OC::$SERVERROOT);
3032
});

lib/Listener/LogListener.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ class LogListener implements IEventListener {
2323
private ?Console $console;
2424

2525
public function __construct(Formatter $formatter, SystemConfig $config) {
26-
if (defined('OC_CONSOLE') && \OC_CONSOLE) {
27-
$level = getenv('OCC_LOG');
28-
if ($level) {
29-
$terminal = new Terminal();
30-
$this->console = new Console($formatter, $config, $level, $terminal->getWidth());
31-
} else {
32-
$this->console = null;
33-
}
26+
$level = getenv('OCC_LOG');
27+
if ($level) {
28+
$terminal = new Terminal();
29+
$this->console = new Console($formatter, $config, $level, $terminal->getWidth());
3430
} else {
3531
$this->console = null;
3632
}

0 commit comments

Comments
 (0)