Location: PHPKode > projects > Online Last.FM Player > class/error.class.php
<?php
// Set error reporting to all for testing
error_reporting(E_ALL);

/////////////////////////////////////////////////////////////////////////////
// Eventualy there will be globals that will get the configs for the class //
// Currently there is simple some variables in there place                 //
/////////////////////////////////////////////////////////////////////////////

global $lcs_error_config;
$lcs_error_config = array();

/* DISPLAY ERROR SETTINGS */

// This setting is sets weither an actual message is shown to the user
// 1 = Errors are shown (For debugging and testing)
// 0 = Errors are not shown (For 'live' use)
$lcs_error_config['display_errors'] = 1;

/* LOG ERROR SETTINGS */

// This setting will set if the error is logged in the error log file or not
// 1 = Errors are logged
// 0 = Errors are not logged
$lcs_error_config['log_errors'] = 1;

// This setting will set the place where the error log will be located
// It must be a path relative to the error class file
// If anything is entered it must end in a '/' (No quotes), if nothing is entered then no '/' is needed
// ONLY USED IF 'LOG_ERRORS' IS SET TO 1
$lcs_error_config['log_file_path'] = '';

// This setting will set what the filename of the error log should be
// ONLY USED IF 'LOG_ERRORS' IS SET TO 1
$lcs_error_config['log_file'] = 'errorLog.txt';

// LEAVE THIS SETTING AS THE DEFAULT
$lcs_error_config['log'] = $lcs_error_config['log_file_path'].$lcs_error_config['log_file'];

class lcs_error {
	var $settings;
	
	function lcs_error () {
		$this->settings = $GLOBALS['lcs_error_config'];
	}
	
	function error ($className, $error, $line, $filename, $die) {
		if ( $die == 'y' ) {
			$errorType = 'Fatal error';
		}
		else {
			$errorType = 'Error';
		}
		if ( $this->settings['display_errors'] == 1 ) {
			$this->_display($className, $error, $line, $filename, $errorType);
		}
		if ( $this->settings['log_errors'] == 1 ) {
			if ( !$this->_log($className, $error, $line, $filename, $errorType) ) {
				echo '<b>Error:</b> Could not write to error log.';
			}
		}
		if ( $this->settings['display_errors'] == 1 && $die == 'y' ) {
			die();
		}
	}
	
	function _display ($className, $error, $line, $filename, $errorType) {
		echo '<b>'.$errorType.': <i>'.$className.':</i></b> '.$error.' <b>on line <i>'.$line.'</i> in <i>'.$filename."</i></b><br />\n";
	}
	
	function _log($className, $error, $line, $filename, $errorType) {
		if ( $file = fopen($this->settings['log'], 'a') ) {
			$text = $errorType.':'.$className.':'.$error.':'.$line.':'.$filename."\n";
			if ( fwrite($file, $text) ) {
				return TRUE;
			}
			else {
				return FALSE;
			}
		}
		else {
			return FALSE;
		}
	}
}

$lcs_loadedClass['error.class.php'] = 1;

?>
Return current item: Online Last.FM Player