Skip to content

Commit

Permalink
Add debugv method and increase client debug verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
donhardman committed Feb 21, 2024
1 parent 275c074 commit 4946a85
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ManticoreSearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 15 additions & 2 deletions src/Tool/Buddy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4946a85

Please sign in to comment.