From 4946a85b3e08feaeea2c11d7a6a70f568053bb51 Mon Sep 17 00:00:00 2001 From: Don Hardman Date: Wed, 21 Feb 2024 12:29:01 +0700 Subject: [PATCH] Add debugv method and increase client debug verbosity --- src/ManticoreSearch/Client.php | 2 +- src/Process/Process.php | 2 +- src/Tool/Buddy.php | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/ManticoreSearch/Client.php b/src/ManticoreSearch/Client.php index 475c732..dc2ae43 100644 --- a/src/ManticoreSearch/Client.php +++ b/src/ManticoreSearch/Client.php @@ -139,7 +139,7 @@ public function sendRequest( $result = $this->responseBuilder->fromBody($this->response); $time = (int)((microtime(true) - $t) * 1000000); - Buddy::debug("[{$time}µs] manticore request: $request"); + Buddy::debugv("[{$time}µs] manticore request: $request"); return $result; } diff --git a/src/Process/Process.php b/src/Process/Process.php index c296a8d..6c1e83d 100644 --- a/src/Process/Process.php +++ b/src/Process/Process.php @@ -75,7 +75,7 @@ public function start(): self { * @return static */ public function execute(string $method, array $args = []): static { - Buddy::debug("[process] execute: $method " . json_encode($args)); + Buddy::debugv("[process] execute: $method " . json_encode($args)); $this->process->write(serialize([$method, $args])); return $this; } diff --git a/src/Tool/Buddy.php b/src/Tool/Buddy.php index 9e4c553..45864eb 100644 --- a/src/Tool/Buddy.php +++ b/src/Tool/Buddy.php @@ -41,16 +41,29 @@ public static function info(string $message, string $eol = PHP_EOL): void { * * @param string $message * @param string $eol + * @param int $verbosity 1 * @return void */ - public static function debug(string $message, string $eol = PHP_EOL): void { - if (!getenv('DEBUG')) { + public static function debug(string $message, string $eol = PHP_EOL, int $verbosity = 1): void { + $debug = (int)getenv('DEBUG'); + if ($debug < $verbosity) { return; } echo "{$message} {$eol}"; } + /** + * Wrapper to display message with higher level of the verbosity + * + * @param string $message + * @param string $eol + * @return void + */ + public static function debugv(string $message, string $eol = PHP_EOL): void { + static::debug($message, $eol, 2); + } + /** * Get version that is read from the file we provided before * Normally it's done on initialization stage of the Buddy base