Login   Register  
PHP Classes
elePHPant
Icontem

File: arberr.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Paul Arbogast  >  arbplate  >  arberr.php  >  Download  
File: arberr.php
Role: ???
Content type: text/plain
Description: error handling routines for arbplate
Class: arbplate
Author: By
Last change:
Date: 2001-12-17 01:27
Size: 3,526 bytes
 

Contents

Class file image Download
<?php
//
// File: arberr.php
//  Ver: 0.8a
// Desc: Error reporting/Logging for arbplate
// Auth: Paul Arbogast 
// *******************
// Latest version is available at http://arbplate.sourceforge.net
// Send Questions or comments to arbo@att.net
// *******************

/* Copyright (C) 2001 Paul Arbogast

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/


// function: arberr
//   called: by system, as replacement for default PHP error handler
//
function arberr ( $argErrNo , $argErrStr , $argErrFile , $argErrLine , $argErrContent ) {
  
   global $ARB_CONFIG;

   $tmpErrStr = "";

   error_reporting( E_ALL );
   
   switch ( $argErrNo ) {

     case E_ERROR :           // fatal error occured, print msg and die
	 case E_USER_ERROR :

	   $tmpErrStr = "[FATAL: #(" . $argErrNo . ") " . $argErrStr . ", in File: " . $argErrFile . ", Line: ". $argErrLine ."]";
	   echo $tmpErrStr . "<br />";
	   die();
	   break;

     case E_WARNING :         // error occured, print msg and continue
	 case E_USER_WARNING :

	   $tmpErrStr = "[ERROR: #(" . $argErrNo . ") " . $argErrStr . ", in File: " . $argErrFile . ", Line: ". $argErrLine ."]";
       echo $tmpErrStr . "<br />";
	   break;

     case E_NOTICE :          // warning, don't print msg, just continue on
     case E_USER_NOTICE :

	   $tmpErrStr = "[WARNING: #(" . $argErrNo . ") " . $argErrStr . ", in File: " . $argErrFile . ", Line: ". $argErrLine ."]";
	   break;

     default :

	   $tmpErrStr = "[UNKOWN: #(" . $argErrNo . ") " . $argErrStr . ", in File: " . $argErrFile . ", Line: ". $argErrLine ."]";
	   break;

   }
   
   if ( $ARB_CONFIG['ERR_LOG'] ) {

     // write to error log
	 if ( ! ( file_exists(  $ARB_CONFIG['ERR_LOG_FILE'] ) ) ) {

	   if ( ! ( $fp = fopen (  $ARB_CONFIG['ERR_LOG_FILE'] , "w" ) ) ) {
	 
		 trigger_error( "Can not open Log file." , E_USER_ERROR ) ;  // cause error that will halt system
         
	   } 
	   else
	   {
	     if ( ! ( fwrite( $fp , "%%% arbplate error log\r\n%%% log created: " . date("F j, Y, g:i a") . "\r\n----------\r\n" ) ) ) {
		 
		   fclose( $fp );
		   trigger_error( "Can not create Log file." , E_USER_ERROR );
		 
		 } 
		 else 
		 {
		   fclose( $fp );
		 }
	   }
	 }
	 
	 if ( ! ( error_log( date( "H:i-md-" ) . getenv('REMOTE_ADDR') . "-" . $tmpErrStr . "\r\n" , 3,  
	          $ARB_CONFIG['ERR_LOG_FILE'] ) ) ) {

	   trigger_error( "Can not write to Log file." , E_USER_ERROR );

	 }

   }

}


// function: set_arberr
//      use: to set function 'arberr' as PHP error handler
//
function set_arberr ( ) {

  set_error_handler( "arberr" ) ;
    
}


// function: unset_arberr
//      use: to reset the default PHP error handler
//  
function unset_arberr ( ) {

  restore_error_handler();

}

?>