Help with error handler function?

hi ,

i wrote a function to handle php errors in my script … but i have problem , i’m trying to trace line & file name in every errors occure , to determine actually where is the error cause …

i used exception class in my function then used getTrace method to trace details of source error …

but my problem that it give me long array , and the array include really source of error details such as file path which contain error and line of error …

so my question is how to extract actually details for every error occure from this long array …

my error handler function is :


public static function error($errno, $errstr, $errfile, $errline)
		{
            $exception  =   new ErrorException();
            $err = $exception->getTrace();

            switch($errno)
                {
                    case E_ERROR:
                    case E_USER_ERROR:                        
                        $type       =   'Fatal Error';
                        $message	=	self::write_log($type,$errstr,$err['1']['file'],$err['1']['line'],$errfile,true);

            			self::msg('php',$message);
                        break;
                        
                    case E_WARNING:
                    case E_USER_WARNING:
                        $type   =   'Warning';
                        self::write_log($type,$errstr,$err['0']['file'],$err['0']['line'],$errfile);
                        break;
                        
                    case E_NOTICE:
                    case E_STRICT:
                    case E_USER_NOTICE:
                        $type   =   'Notice';
                        self::write_log($type,$errstr,$err['0']['file'],$err['0']['line'],$errfile);
                        break;
                        
                    case E_RECOVERABLE_ERROR:
                        $type   =   'Catchable';
                        self::write_log($type,$errstr,$err['0']['file'],$err['0']['line'],$errfile);
                        break;
                    
                    default:
                        $type   =   'Unknown Error';
                        self::write_log($type,$errstr,$err['0']['file'],$err['0']['line'],$errfile);
                        break;
                }
		}

with note that i use trigger_error function to tell about errors …

so help me plz to extract true details about every error occure in any part of my script fomt the method getTrace().

thx :slight_smile:

Have you checked your PHP error_log file? It is comprehensive and can be tailored to suit your requirements.

Here is a sample from my error_log:



[10-Jun-2010 21:06:53] PHP Parse error:  
	syntax error, unexpected $end in 
	/home/XXXXXXXXX/YYYYYYYY//m_lib.php on line 1378

[12-Jun-2010 20:27:53] PHP Warning:  
	Cannot modify header information - headers already sent by 
	(output started at /home/XXXXXXXXX/YYYYYYYY/kill.php:2) in /home/XXXXXXXXX/YYYYYYYY/charles.php on line 19

[12-Jun-2010 20:52:25] PHP Fatal error:  
	Call to undefined function error_level() in 
	/home/XXXXXXXXX/YYYYYYYY/henry.php on line 2

[12-Jun-2010 20:52:53] PHP Notice:  
	Undefined variable: imgpath in 
	/home/XXXXXXXXX/YYYYYYYY/james.php on line 23

[12-Jun-2010 20:52:53] PHP Notice:  
	Undefined variable: imgpath in 
	/home/XXXXXXXXX/YYYYYYYY/Sydney.php on line 38


Why not spend your time eliminating the errors :slight_smile:

I use a CodeIgniter, a PHP Framework and use this check in my “footer” to warn me of not having an empty error_log file:


<?php 
if (LOCALHOST AND file_exists(LOG_FILE_TODAY) AND  filesize(LOG_FILE_TODAY) > 42))
{
    echo "<div style='position:fixed;top:0px;left:420px;z-index:3210'>";
        echo heading('YES we have errors: ' . LOG_FILE_TODAY,5);
    echo '</div>';	
}
?>


.