Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debugv method and increase client debug verbosity #32

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading