From 4c7f6847fdc069239f00ca824158ba640765c43c Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 26 Sep 2024 13:53:45 +0200 Subject: [PATCH] LSlog::get_debug_backtrace_context(): add & arguments --- src/includes/class/class.LSlog.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/includes/class/class.LSlog.php b/src/includes/class/class.LSlog.php index 3543980b..6706a377 100644 --- a/src/includes/class/class.LSlog.php +++ b/src/includes/class/class.LSlog.php @@ -310,25 +310,34 @@ class LSlog { /** * Generate current context backtrace - * + * @param bool $with_args Add args (optional, default: false) + * @param int|null $ignore_last_frames Ignore last frames (optional, default: 1) * @return string Current context backtrace **/ - public static function get_debug_backtrace_context() { + public static function get_debug_backtrace_context($with_args=false, $ignore_last_frames=null) { $traces = debug_backtrace(); if (!is_array($traces) || count($traces) < 2) return "unknown context"; $msg = array(); $j=0; - for ($i=count($traces)-1; $i >= 1; $i--) { + for ($i=count($traces)-1; $i >= (is_int($ignore_last_frames)?$ignore_last_frames:1); $i--) { $j += 1; $trace = array("#$j"); if (isset($traces[$i]['file'])) $trace[] = $traces[$i]['file'].(isset($traces[$i]['line'])?":".$traces[$i]['line']:""); + $args = ( + $with_args && isset($traces[$i]["args"])? + format_callable_args($traces[$i]["args"]): + "" + ); if (isset($traces[$i]['class']) && isset($traces[$i]['function'])) - $trace[] = $traces[$i]['class'] . " " . $traces[$i]['type'] . " " . $traces[$i]['function']. "()"; + $trace[] = sprintf( + "%s %s %s(%s)", + $traces[$i]['class'], $traces[$i]['type'], $traces[$i]['function'], $args + ); elseif (isset($traces[$i]['function'])) - $trace[] = $traces[$i]['function']. "()"; + $trace[] = sprintf("%s(%s)", $traces[$i]['function'], $args); $msg[] = implode(" - ", $trace); }