Error handling and BackTrace
| From: | xavier | Date: | Wed, 12 Mar 2003 16:38:01 +0000 |
| Subject: | Error handling and BackTrace | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-4183@lists.php.net to get a copy of this message | ||
Hi All,
i'me trying to define a personnal function to handle errors with :
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "my_error");
and log it in a file.
In my log file, i would like to put the file name and the line number of the script wich initiate the error.
Those infos are avalaible from the getBacktrace() method of the pear error object, but i don't know the best way to extract those datas ?
Is the origin caller script always the last in the backtrace array ? For now i've done a thing like that :
------------------------------------------------------------------------
function my_error($erreur) {
global $errorlog;
$backtrace = $erreur->getBacktrace();
$backtrace = array_reverse($backtrace);
$line = $backtrace[0]['line'];
$file = $backtrace[0]['file'];
$errorlog->log($erreur->getMessage() . " - Line: " . $line . "- File: " . basename($file) , PEAR_LOG_ALERT);
}
------------------------------------------------------------------------
But i'me sur there is a better way to do that...
Thanks
Regards
--
Xavier