aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-07-02 16:02:44 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-07-02 16:02:44 +0200
commit9baf8fea8c6faf88ddf0fc969426b893f2fe2071 (patch)
treeb70b18f37e82139cc7584b8c955e489e37ececab /core
parent2ba0819243cfe5eedf148b6ff19d5070f1ff7844 (diff)
downloadnextcloud-server-9baf8fea8c6faf88ddf0fc969426b893f2fe2071.tar.gz
nextcloud-server-9baf8fea8c6faf88ddf0fc969426b893f2fe2071.zip
fix(occ): Move debug log listener setup to a static method, add option for level
Also changed option from --debug to --debug-log to avoid conflicts Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'core')
-rw-r--r--core/Listener/BeforeMessageLoggedEventListener.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/Listener/BeforeMessageLoggedEventListener.php b/core/Listener/BeforeMessageLoggedEventListener.php
index d6ebcfa50ad..a0581f25830 100644
--- a/core/Listener/BeforeMessageLoggedEventListener.php
+++ b/core/Listener/BeforeMessageLoggedEventListener.php
@@ -10,18 +10,28 @@ declare(strict_types=1);
namespace OC\Core\Listener;
use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\EventDispatcher\IEventListener;
use OCP\Log\BeforeMessageLoggedEvent;
+use OCP\Server;
/**
* Listen to log calls and output them to STDOUT for debug purposes
* @template-implements IEventListener<BeforeMessageLoggedEvent>
*/
class BeforeMessageLoggedEventListener implements IEventListener {
+ public function __construct(
+ private int $level,
+ ) {
+ }
+
public function handle(Event $event): void {
if (!$event instanceof BeforeMessageLoggedEvent) {
return;
}
+ if ($event->getLevel() < $this->level) {
+ return;
+ }
echo
match($event->getLevel()) {
0 => '[debug]',
@@ -35,4 +45,24 @@ class BeforeMessageLoggedEventListener implements IEventListener {
.$event->getMessage()['message']
."\n";
}
+
+ /**
+ * Register listener to log messages and remove debug options from $_SERVER['argv']
+ */
+ public static function setup(): void {
+ $eventDispatcher = Server::get(IEventDispatcher::class);
+ $argv = $_SERVER['argv'];
+ $level = 0;
+ foreach ($argv as $key => $arg) {
+ if ($arg === '--debug-log') {
+ unset($argv[$key]);
+ } elseif (str_starts_with($arg, '--debug-log-level=')) {
+ $level = (int)substr($arg, strlen('--debug-log-level='));
+ unset($argv[$key]);
+ }
+ }
+ $_SERVER['argv'] = array_values($argv);
+ $debugLoggerEventListener = new self($level);
+ $eventDispatcher->addListener(BeforeMessageLoggedEvent::class, $debugLoggerEventListener->handle(...));
+ }
}