diff options
-rw-r--r-- | it_debug.class | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/it_debug.class b/it_debug.class index f5122ea..8f2c441 100644 --- a/it_debug.class +++ b/it_debug.class @@ -223,15 +223,54 @@ static function dump($args, $p = []) */ static function backtrace($p = array()) { - foreach (self::debug_backtrace($p) as $call) + $frames = $p['trace'] ?: ($p['format'] ? array_slice(debug_backtrace(0), $p['skiplevels']) : null); + + if ($p['format'] == "long") + { + foreach ($frames as $frame) + if ($tracesize < 100000 && ($tracesize += strlen(print_r($frame, true))) < 100000) # save mem + $frames[] = $frame; + $result = $frames ? print_r($frames, true) . "\n" : null; + } + else if ($p['format'] == "medium") + { + foreach ($frames as $frame) + { + $locations[] = basename($frame['file']) . ":" . $frame['line']; + + $argstrings = []; + foreach ($frame['args'] as $arg) + { + $t = trim(it::replace(['^array \(\s*' => "[", ',\n\)$' => "]", " +" => " ", "\n" => "", var_export($arg, true)]), " ,"); + $argstrings[] = strlen($t) < 80 ? $t : it::replace(["(.{0,60} |.{0,60}).*" => '$1'], $t) . "..." . (is_array($arg) ? "]" : (is_object($arg) ? "}" :"")); + } + + $allargs = join(", ", $argstrings); + if ($frame['type'] == "->" || $frame['type'] == "::") + $funcs[] = $frame['class'] . $frame['type'] . $frame['function'] . "($allargs)"; + else + $funcs[] = $frame['function'] . "($allargs)"; + + $maxlen = max(it::map('strlen', $locations)); + } + + foreach ($locations as $idx => $location) + $result .= substr($location . " ", 0, $maxlen) . " " . $funcs[$idx] . "\n"; + } + else { - $fn = $call['file']; - $fn = (it::match('auto_prepend', $fn) ? basename(dirname(dirname($fn))) . "/" : (it::match('/(cgi|bin)/', $fn) ? basename(dirname($fn)) . "/" : "")) . basename($fn); - if ($fn) - $result[] = $fn . ":" . $call['line']; + foreach (self::debug_backtrace($p) as $call) + { + $fn = $call['file']; + $fn = (it::match('auto_prepend', $fn) ? basename(dirname(dirname($fn))) . "/" : (it::match('/(cgi|bin)/', $fn) ? basename(dirname($fn)) . "/" : "")) . basename($fn); + if ($fn) + $result[] = $fn . ":" . $call['line']; + } + + $result = implode(" ", (array)$result); } - return implode(" ", (array)$result); + return $result; } static function set($debug_string) |