From e156208e9d7661aa433abee8e261ed8a9a9749fa Mon Sep 17 00:00:00 2001 From: brettp Date: Fri, 22 Apr 2011 21:14:28 +0000 Subject: Added 3rd param to elgg_deprecated_notice() to control how much of the stack to show. git-svn-id: http://code.elgg.org/elgg/trunk@9014 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index e9172d184..8967d9c6c 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1152,13 +1152,16 @@ function elgg_dump($value, $to_screen = TRUE, $level = 'NOTICE') { * * @see CODING.txt * - * @param str $msg Message to log / display. - * @param str $dep_version Human-readable *release* version: 1.7, 1.7.3 + * @param str $msg Message to log / display. + * @param str $dep_version Human-readable *release* version: 1.7, 1.7.3 + * @param int $backtrace_level How many levels back to display the backtrace. Useful if calling from + * functions that are called from other places (like elgg_view()). Set + * to -1 for a full backtrace. * * @return bool * @since 1.7.0 */ -function elgg_deprecated_notice($msg, $dep_version) { +function elgg_deprecated_notice($msg, $dep_version, $backtrace_level = 1) { // if it's a major release behind, visual and logged // if it's a 1 minor release behind, visual and logged // if it's for current minor release, logged. @@ -1192,9 +1195,26 @@ function elgg_deprecated_notice($msg, $dep_version) { // Get a file and line number for the log. Never show this in the UI. // Skip over the function that sent this notice and see who called the deprecated // function itself. + $msg .= " Called from "; + $stack = array(); $backtrace = debug_backtrace(); - $caller = $backtrace[1]; - $msg .= " (Called from {$caller['file']}:{$caller['line']})"; + // never show this call. + array_shift($backtrace); + $i = count($backtrace); + + foreach ($backtrace as $trace) { + $stack[] = "[#$i] {$trace['file']}:{$trace['line']}"; + $i--; + + if ($backtrace_level > 0) { + if ($backtrace_level <= 1) { + break; + } + $backtrace_level--; + } + } + + $msg .= implode("
-> ", $stack); elgg_log($msg, 'WARNING'); -- cgit v1.2.3