diff --git a/framework/helper.class.php b/framework/helper.class.php index 4cfa7a2fd4..d29557aaf1 100644 --- a/framework/helper.class.php +++ b/framework/helper.class.php @@ -810,21 +810,31 @@ function getVisions(): array } /** - * Save any message with any type to the php log file which prefix with 'php.'. + * Save debug log to the php log file which prefix with 'debug.'. * - * @param mixed $message - * @param string $file - * @param int $line + * @param mixed $message * @return void */ -function debug($message = '', $file = 'undefined', $line = 0) +function debug($message = ''): void { - if(!is_string($message)) $message = (string)json_encode($message, JSON_PRETTY_PRINT); + static $times = []; + $time = microtime(true); + $duration = $times ? $time - end($times) : 0; + $times[] = $time; - if(empty($file) || $file == 'undefined') $message .= (new Exception())->getTraceAsString(); + static $counts = []; + $count = $counts ? end($counts) + 1 : 1; + $counts[] = $count; global $app; - $app->saveError(E_USER_WARNING, $message, $file, $line); + $logFile = $app->getLogRoot() . 'debug.' . date('Ymd') . '.log.php'; + $uid = $_SERVER['HTTP_X_ZIN_UID'] ?? ''; + $count = sprintf('%04d', $count); + $time = date('H:i:s'); + $duration = round($duration, 3); + if($duration < 0.001) $duration = 0.001; + if(is_object($message) || is_array($message)) $message = json_encode($message, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + file_put_contents($logFile, $count . ($uid ? " uid=$uid" : '') . " time=$time duration={$duration}s message=$message\n", FILE_APPEND); } /**