PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Logging » Log » Bug #7602

Error on _getBacktraceVars for composite log

Details

Submitted2006-05-11 09:25 UTC
Fromd dot lippi at comune dot prato dot it
Assignedjon
StatusClosed
PackageLog
PHP Version5.0.3
OSFedora Linux
Roadmaps(Not assigned)

Comments

[2006-05-11 09:25 UTC] d dot lippi at comune dot prato dot it

Description:
------------
Function _format() of Log.php set $file to composite.php, $line to 120 and $func to log() if you use the composite log.

Test script:
---------------
I change my Log->_getBacktraceVars() function in this way:

function _getBacktraceVars($depth)
{
/* Start by generating a backtrace from the current call (here). */
$backtrace = debug_backtrace();

/*
* However, if log() was called from one of our "shortcut" functions, or the function log of composite Log
* we're going to need to go back an additional step.
*/
$i = $depth;
do {
$file = @$backtrace[$i]['file'];
$line = @$backtrace[$i]['line'];
$func = @$backtrace[++$i]['function'];
} while (in_array($func, array('emerg', 'alert', 'crit', 'err', 'warning',
'notice', 'info', 'debug', 'log'))===TRUE && is_null($func)===FALSE);

/*
* If we couldn't extract a function name (perhaps because we were
* executed from the "main" context), provide a default value.
*/
if (is_null($func)) {
$func = '(none)';
}

/* Return a 3-tuple containing (file, line, function). */
return array($file, $line, $func);
}

This solution have a problem, if the function that call log() is called emerg, alert, crit, ..., log the function _getBacktraceVars go back another level in the backtrace.