From 7968fef4b6d5fe23aa13b86c662a4aa89c9171b4 Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 2 Oct 2026 10:42:20 +0200 Subject: [PATCH] Only format debug log arguments when a logger is set VipsObject::get() and VipsOperation::callBase() ran var_export() for their debug log on every call, and Introspect cast itself to a string, even though debugLog() drops the message when no logger is set. --- CHANGELOG.md | 1 + src/Introspect.php | 4 +++- src/VipsObject.php | 5 ++++- src/VipsOperation.php | 9 ++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81d970bf..339e85df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to `php-vips` will be documented in this file. - better ffi startup diagnostics [ping-localhost] - add setBlock() and setBlockUntrusted() to control operation blocking [jcupitt] +- only format debug log arguments when a logger is set [guillaume-sainthillier] ## 2.6.1 - 2025-12-10 diff --git a/src/Introspect.php b/src/Introspect.php index 489364d7..92d419c2 100644 --- a/src/Introspect.php +++ b/src/Introspect.php @@ -197,7 +197,9 @@ public function __construct($operation_name) array_splice($this->method_args, $index); } - Utils::debugLog($operation_name, ['introspect' => strval($this)]); + if (Config::getLogger() !== null) { + Utils::debugLog($operation_name, ['introspect' => strval($this)]); + } } public function __toString(): string diff --git a/src/VipsObject.php b/src/VipsObject.php index e0b18a59..43d606ad 100644 --- a/src/VipsObject.php +++ b/src/VipsObject.php @@ -162,7 +162,10 @@ public function get(string $name) g_object_get_property($this->gObject, $name, $gvalue->pointer); $value = $gvalue->get(); - Utils::debugLog("get", [$name => var_export($value, true)]); + // var_export() is costly, only run it when the message is logged + if (Config::getLogger() !== null) { + Utils::debugLog("get", [$name => var_export($value, true)]); + } return $value; } diff --git a/src/VipsOperation.php b/src/VipsOperation.php index cf212afa..758b0836 100644 --- a/src/VipsOperation.php +++ b/src/VipsOperation.php @@ -339,9 +339,12 @@ public static function callBase( $result = self::wrapResult($result); - Utils::debugLog($operation_name, [ - 'result' => var_export($result, true) - ]); + // var_export() is costly, only run it when the message is logged + if (Config::getLogger() !== null) { + Utils::debugLog($operation_name, [ + 'result' => var_export($result, true) + ]); + } return $result; }